我在使用子进程模块的Python中遇到了问题。我想使用check_output函数执行3个进程。当我尝试在下一段代码中解释时,每个过程都依赖于之前执行的过程:
command_line_1 = '/home/user/fd/first_step.py' +" " + STATIC_FILE
args1 = shlex.split(command_line_1)
res1 = subprocess.check_output(args1)
command_line_2 = '/home/user/fd/second_step.py <' + " " + **the output file of res1**
args2 = shlex.split(command_line_2)
res2 = subprocess.check_output(args2)
我读了其他问题,我写了类似的东西。但是,它不起作用:
command_line_1 = '/home/user/fd/first_step.py' +" " + STATIC_FILE
args1 = shlex.split(command_line_1)
process1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
command_line_2 = '/home/user/fd/second_step.py <'
args2 = shlex.split(command_line_2)
process2 = subprocess.Popen(args2,stdin=process1.stdout, stdout=subprocess.PIPE)
我做错了什么?
谢谢!