我需要在shell“MYSHELL>;”启动后向它发送命令。在
prcs = subprocess.Popen("MYSHELL; cmnd1; cmnd2;",shell=True,
subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outputPrcs, err = prcs.communicate()
print outputPrcs
问题只实现了进入shell,其他命令(cmnd1;cmnd2;)不被发送。在
结果: MYSHELL>
如果要将输入发送到shell,则应将其作为
communicate
中的参数传递,如下所示:测试:
^{pr2}$从docs:
注意,
Wait for process to terminate.
我想你需要的是{a2}。它不在标准库中,但它可以满足您的需要。在示例:
^{pr2}$输出:
相关问题 更多 >
编程相关推荐