我有以下 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]
关于python - 使用 python 将输入发送到使用子进程打开的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27202490/