相关疑难解决方法(0)

新手python子进程:"写入错误:断管"

感谢以下有用的建议:

所以我似乎已经修好了

  1. 将命令分离为对Popen的单独调用
  2. stderr = subprocess.PIPE作为每个Popen链的参数.

新代码:

import subprocess
import shlex
import logging

def run_shell_commands(cmds):
    """ Run commands and return output from last call to subprocess.Popen.
        For usage see the test below.
    """
    # split the commands
    cmds = cmds.split("|")
    cmds = list(map(shlex.split,cmds))

    logging.info('%s' % (cmds,))

    # run the commands
    stdout_old = None
    stderr_old = None
    p = []
    for cmd in cmds:
        logging.info('%s' % (cmd,))
        p.append(subprocess.Popen(cmd,stdin=stdout_old,stdout=subprocess.PIPE,stderr=subprocess.PIPE))
        stdout_old = p[-1].stdout
        stderr_old = p[-1].stderr
    return p[-1]


pattern = '"^85567      "'
file …
Run Code Online (Sandbox Code Playgroud)

python subprocess popen

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

popen ×1

python ×1

subprocess ×1