2011年(264)
分类: Python/Ruby
2011-08-28 14:44:52
Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.
returns a tuple (stdoutdata, stderrdata).
这个方法的作用就是为了通讯!即父子进程之间的管道是基于这个进行通讯的!
所以可以这样做:
def run_exe(fail_if_stderr=False, encoding="utf-8"):
cmd = find_program("csystem.exe")
pipe = Popen([cmd] , executable=cmd, stdout=PIPE, stderr=PIPE,stdin=PIPE)
time.sleep(5)
out, err = pipe.communicate('0\n')