subprocess.call不工作在PyCharm(linux)

这个程序是:

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"])