修改自:
原文 : Working with Python subprocess - Shells, Processes, Streams, Pipes, Redirects and More
地址 : http://jimmyg.org/blog/2009/working-with-python-subprocess.html
一 程序的stdin,stdout,stderr+redirect+pipe
程序的stdin,stdout,stderr:
通常地一个应用程序默认地连接有3个io流,分别为stdin标准输入流,stdout标准输出流,stderr标准错误输出流。在程序中我们可以使用它们的句柄0,1,2来使用它们。
程序与流的工作过程如下:
从终端的输入通过标准输入流传给程序,程序的输出传给标准输出流,程序的错误传给标准错误输出流。
程序的流的重定向(redirect):
例如将程序的输入重定向到一个文件file1,将输出和错误输出重定向到文件file2,语句如下:program < f