[英]subprocess.call not working in PyCharm (linux)
这是程序:
if os.name == 'posix' and getpass.getuser() != 'root':
from subprocess import call
call(["sudo", sys.executable, os.path.realpath(__file__), "--root-install"])
当我从终端运行它时工作正常:
> [sudo] Password for user:
但是当我从PyCharm运行时,终端只是空白。
我也尝试手动设置stdin=sys.stdin, stdout=sys.stdout
,但这并没有改变任何东西。
我在这做错了什么?
PyCharm和IDE通常不喜欢类似getpass
的输入。 由于sudo
以这种方式请求密码,因此它不能从重定向的IDE控制台运行。
从Popen
重定向stdin
也不会改变任何东西。
解决方法:从终端运行sudo
命令。 xterm
示例(对不起,我对现在的终端了解不多):
call(["xterm","-e","sudo", sys.executable, os.path.realpath(__file__), "--root-install"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.