子进程中的参考文件 (Python)
Reference file during subprocess (Python)
已获取写入文件的列表:
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)
已获取写入文件的列表:
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)