I have some program (let's call it some_program) that prints to stdout, so when I run from my terminal the command below, a new file is been created (test.bin) with the content that was generated from the stdout of some_program:
some_program | tee test.bin
However, when I try to run some_program from a python script (python-3.6) and pipe it into tee to create the file test.bin, it doesn't work. I do see that some_program is running and done it's work, but test.bin wasn't created.
Here is my python script:
import subprocess
import os
CURR_DIR = os.getcwd()
OUTPUT_FILE = CURR_DIR + '/test.bin'
subprocess.check_output(['some_program', '|', 'tee', '{}'.format(OUTPUT_FILE)])
Any ideas?
Thanks
P.S.
I workaround it with this:
stdout = subprocess.run(['some_program'], stdout=subprocess.PIPE).stdout
f = open(OUTPUT_FILE, 'wb')
f.write(stdout)
f.close()
But I'm still curious why it doesn't work when piping with tee.