子流程期间的引用文件(Python)
已获取写入文件的列表:子流程期间的引用文件(Python),python,list,subprocess,Python,List,Subprocess,已获取写入文件的列表: f=open('/tmp/list.txt','w') f.write(list) 然后需要在子流程中使用f的内容 process = subprocess.Popen('oscommand **--file=f**, shell=True, stdout=subprocess.PIPE) oscommand如何读取f的内容?您需要将文件名传递给子进程命令,而不是文件对象: f = open('/tmp/list.txt','w') f.write(list) f.
f=open('/tmp/list.txt','w')
f.write(list)
然后需要在子流程中使用f的内容
process = subprocess.Popen('oscommand **--file=f**, shell=True, stdout=subprocess.PIPE)
oscommand如何读取f的内容?您需要将文件名传递给子进程命令,而不是文件对象:
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)