簡體   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