![](/img/trans.png)
[英]Running a list command strings with subprocess popen and getting the output
[英]getting output of command in subprocess
我看到了一些線程,但是那里的所有內容都幫不了我。
我正在運行一個子進程以通過python(使用2.7)在cmd上運行命令
p = subprocess.Popen(["start", "cmd", "/k", command], shell=True)
該命令可以正常工作,但是我無法捕獲該命令的輸出。
我嘗試了check_output
或指定了stdout=sp.PIPE
或stdout=file
,但是沒有用。
任何建議將不勝感激。
謝謝
check_output
應該可以正常工作:
from subprocess import check_output
out = check_output(["echo", "Test"], shell=True)
命令輸出:
>>> print out
Test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.