如何实现以下功能:
python执行shell命令,该命令等待用户
在用户键入input
后,程序会响应一些input
python捕获
最佳答案
您可能需要subprocess.Popen
。要与流程通信,您将使用communicate
方法。
例如
process=subprocess.Popen(['command','--option','foo'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
inputdata="This is the string I will send to the process"
stdoutdata,stderrdata=process.communicate(input=inputdata)
关于python - Python执行命令行,发送输入和读取输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10673185/