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