Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1378705
  • 博文数量: 264
  • 博客积分: 5810
  • 博客等级: 大校
  • 技术积分: 3528
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 17:15
文章分类

全部博文(264)

文章存档

2011年(264)

分类: Python/Ruby

2011-08-28 14:44:52

  1. pipe = Popen([cmd] , executable=cmd, stdout=PIPE, stderr=PIPE,stdin=PIPE)
  2. 如果需要让子进程输入数据的话需要指明stdin的输入为管道
  3. Popen.communicate(input=None)

    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')

阅读(997) | 评论(0) | 转发(0) |
0

上一篇:groovy简介

下一篇:NOSQL精华必读

给主人留下些什么吧!~~