p = subprocess.Popen(['someapp', 'param1', 'param2'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,)
# sends the command "some_command" to the app:
p.stdin.write('some_command\n')
# waits for a single line from the output
result = p.stdout.readline()
在运行子进程时,您正在启动的应用程序的行为可能会有所不同。具体地说,当连接到流程管道时,一些应用程序在默认情况下缓冲其输出,而不是逐行刷新。如果正在运行的应用程序刷新其输出,则可以实时获取,否则,只有在缓冲区已满时才能获取输出。你知道吗
也就是说,下面是一个运行某个应用程序的示例:
如果它挂起
p.stdout.readline()
,这意味着输出正在被缓冲。你知道吗相关问题 更多 >
编程相关推荐