Trying to redirect a subprocess' output to a file.
server.py:
while 1:
print "Count " + str(count)
sys.stdout.flush()
count = count + 1
time.sleep(1)
Laucher:
cmd = './server.py >temp.txt'
args = shlex.split(cmd)
server = subprocess.Popen( args )
The output appear on screen, temp.txt
remains empty.
What am I doing wrong?
As background I am trying to capture the output of a program that has already been written.
I cannot use:
server = subprocess.Popen(
[exe_name],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
as the program may not flush.
Instead I was going to redirect output through a fifo. This works fine if I manually launch server.py but obviously not if I Popen()
cause redirect doesnt work.
ps -aux
shows that server.py
was launched correctly.