Java 调用 Python 脚本卡在 sudo 密码提示符上
我正在开发一个在后台调用 python 脚本的 Java 应用程序。
这是我调用 python 脚本的方式:
Runtime r = Runtime.getRuntime();
Process p = r.exe("/path/to/Python/script.py");
我可以看到我的 python 脚本使用 ps 在后台运行。
该脚本需要 root 权限,因此 sudo 会提示输入密码。
我已经看到了 2 个解决方案:
- 导入 Python 模块 pExpect 并在显示时填写 sudo。
- 将 jython java 模块添加到我的库中。
它们都是我的应用程序的开销,我不需要与脚本交互,我只是希望它在后台运行。
有没有办法在 UI 中弹出 SUDO,以便用户进行交互并继续?
谢谢。
I am developing a Java application that calls a python script behind the scene.
This is the way i call my python script:
Runtime r = Runtime.getRuntime();
Process p = r.exe("/path/to/Python/script.py");
I can see that my python script running in the background using ps.
The script requires root privileges so sudo prompts for password.
I have seen 2 solutions for this:
- Import Python Module pExpect and fill sudo as it shows up.
- Add jython java module to my library.
Both of them are overhead to my application, i don't need to interact with the script, i just want it to run in the background.
Is there a way to pop SUDO in UI, so user will interact and continue?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 gksudo 代替 sudo。它会自动弹出一个窗口,要求输入密码。
Use gksudo in place of sudo. It automatically pops up a window asking for the password.