2016-03-23 5 views
2

Got Liste, die in eine Datei geschrieben wird:Referenzdatei während subprocess (Python)

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

f.write(list) 

Inhalt von f muss dann in subprocess verwendet werden

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

Wie kann Inhalte von f von oscommand einlesen?

Antwort

3

Sie müssen Dateinamen Teilprozess-Befehl übergeben, nicht Objekt-Datei:

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) 
Verwandte Themen