当我执行实用程序 blab 时,它会询问是或否以进行确认,我该怎么办?谢谢,
代码如下:
proc = subprocess.Popen("blab delete {}".format(num), shell=True,
stderr=subprocess.STDOUT, stdin=subprocess.STDIN)
stdout_value = proc.communicate()[0]
请您参考如下方法:
如果您想使用 Python 将数据发送到进程的标准输入,请使用 stdin=PIPE 创建 Popen 对象。同样,要在结果元组中获得 None 以外的任何内容,您还需要提供 stdout=PIPE 和/或 stderr=PIPE。
from subprocess import PIPE, Popen, STDOUT
process = Popen("blab delete {}".format(num), shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = process.communicate(input=b'yes')[0]
output = output.decode('utf-8')
