linux - Python. Second step of subprocess.Popen truncates results of first -


in snipet of python script below, think temp2 doesn't wait temp finish running, output can large, text. truncates result ('out') temp, stops mid line. 'out' temp works fine until temp 2 added. tried adding time.wait() subprocess.popen.wait(temp). these both allow temp run completion 'out' not truncated disrupt chaining process there no 'out2'. ideas?

temp = subprocess.popen(call, stdout=subprocess.pipe) #time.wait(1) #subprocess.popen.wait(temp) temp2 =  subprocess.popen(call2, stdin=temp.stdout, stdout=subprocess.pipe) out, err = temp.communicate() out2, err2 = temp2.communicate() 

according python docs communicate() can accept stream sent input. if change stdin of temp2 subprocess.pipe , put out in communicate(), data piped.

#!/usr/bin/env python import subprocess import time  call = ["echo", "hello\nworld"] call2 = ["grep", "w"]  temp = subprocess.popen(call, stdout=subprocess.pipe)  temp2 =  subprocess.popen(call2, stdin=subprocess.pipe, stdout=subprocess.pipe) out, err = temp.communicate() out2, err2 = temp2.communicate(out)  print("out:  {0!r}, err:  {1!r}".format(out, err)) # out:  b'hello\nworld\n', err:  none print("out2: {0!r}, err2: {1!r}".format(out2, err2)) # out2: b'world\n', err2: none 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -