[英]Send input to program opened with subprocess using python?
我有以下python代碼,只想在詢問特定問題時向終端發送命令。 這是我到目前為止的
import subprocess
import sys
cmd = "Some application"
dat = str("")
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.communicate(input="this is my input to the subprocess")
如果需要捕獲輸出,請執行以下操作:
output = p.communicate(input="this is my input to the subprocess")[0]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.