2016-03-23 17 views
2

Got listesi: f içeriği nasıl olabilir fReferans dosyası (Python)

f=open('/tmp/list.txt','w') 

f.write(list) 

İçindekiler ihtiyacı sonra alt süreç

process = subprocess.Popen('oscommand **--file=f**, shell=True, stdout=subprocess.PIPE) 

kullanılacak oscommand tarafından okumak?

cevap

3

Sen alt süreç komutuna dosya adı geçmesi gerekiyor, dosyalayamadıysanız nesne:

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)