Reputation: 1759
Got list that gets written out to a file:
f=open('/tmp/list.txt','w')
f.write(list)
Contents of f needs to then be used in subprocess
process = subprocess.Popen('oscommand **--file=f**, shell=True, stdout=subprocess.PIPE)
How can contents of f be read in by oscommand ?
Upvotes: 2
Views: 87
Reputation: 369094
You need to pass file name to sub-process command, not file object:
f = open('/tmp/list.txt','w')
f.write(list)
f.close() # Make sure to close the file before call sub-process.
# Otherwise, file content will not visible to sub-process.
process = subprocess.Popen('oscommand --file={}'.format(f.name),
shell=True, stdout=subprocess.PIPE)
Upvotes: 3