[英]subprocess.call not working in PyCharm (linux)
Here's the program: 这是程序:
if os.name == 'posix' and getpass.getuser() != 'root':
from subprocess import call
call(["sudo", sys.executable, os.path.realpath(__file__), "--root-install"])
When I run it from the terminal it works fine: 当我从终端运行它时工作正常:
> [sudo] Password for user:
But when I run it from PyCharm the terminal just stays blank. 但是当我从PyCharm运行时,终端只是空白。
I have also tried setting stdin=sys.stdin, stdout=sys.stdout
manually, but that did not change anything. 我也尝试手动设置stdin=sys.stdin, stdout=sys.stdout
,但这并没有改变任何东西。
What am I doing wrong here? 我在这做错了什么?
PyCharm and IDEs generally don't like getpass
-like inputs. PyCharm和IDE通常不喜欢类似getpass
的输入。 Since sudo
asks for the password in such a way, it's not runnable from a redirected IDE console. 由于sudo
以这种方式请求密码,因此它不能从重定向的IDE控制台运行。
Redirecting stdin
from Popen
won't change anything either. 从Popen
重定向stdin
也不会改变任何东西。
Workaround: run the sudo
command from a terminal. 解决方法:从终端运行sudo
命令。 Example with xterm
(sorry, I don't know much about nowadays terminals): xterm
示例(对不起,我对现在的终端了解不多):
call(["xterm","-e","sudo", sys.executable, os.path.realpath(__file__), "--root-install"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.