Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
子流程期间的引用文件(Python)_Python_List_Subprocess - Fatal编程技术网

子流程期间的引用文件(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)