【发布时间】:2016-05-29 05:31:27
【问题描述】:
我在 Windows 上有一个交互式 shell 应用程序。 我想编写一个 python 脚本,它将命令发送到该 shell 应用程序并读回响应。 但是我想以交互方式进行,即我希望 shell 应用程序在 python 脚本运行时一直运行。
我试过了
self.m_process subprocess.Popen(path_to_shell_app,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,universal_newlines=True)
然后使用标准输入和标准输出来发送和接收数据。 似乎正在打开 shell 应用程序,但我无法与之通信。
我做错了什么?
【问题讨论】:
-
你可能想看看 subprocess.PIPE 是什么意思
-
如何使用标准输入/标准输出?文档说:Warning 使用communicate() 而不是.stdin.write、.stdout.read 或.stderr.read 以避免由于任何其他操作系统管道而导致的死锁缓冲区填满并阻塞子进程。