繁体   English   中英

subprocess.call无法在PyCharm(linux)中工作

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM