这个程序是:
if os.name == 'posix' and getpass.getuser() != 'root': from subprocess import call call(["sudo", sys.executable, os.path.realpath(__file__), "--root-install"])
当我从terminal运行它工作正常:
> [sudo] Password for user:
但是,当我从PyCharm运行它terminal只是保持空白。
我也尝试手动设置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"])