I'm writing an application which requires using a 3rd party shell script.
This shell script some-script
processes an input file --ifile
and saves the results in an output file --ofile
.
So currently I can write/read to a tmp file and delete them afterwards
import os
ifile_name = '/tmp/ifile.txt'
ofile_name = '/tmp/ofile.txt'
with open(ifile_name, 'w') as f:
# write data to ifile for 'some-script'
# format command
command = 'some-script --ifile {ifile} --ofile {ofile}'.format(
ifile=ifile_name,
ofile=ofile_name
)
os.system(command)
with open(ofile_name, 'r') as f:
# read in data from ofile
# clean up and delete tmp files
Is there a way I can directly pass python data to --ifile
(e.g. by '\n'.join(arr)
) and have the --ofile
stream result as back in script without reading to / writing from files? and just string parse?