subprocess, Kommandozeile
Verfasst: Freitag 30. Juli 2010, 11:36
Zuerstmal sry für die Anfängerfrage *schäm*
Wie ich mit dem subprocess modul die Kommandozeile öffne weiß ich.
Gibt es jetzt einen Weg das Pythonproramm automatisch etwas in die Kommandozile eintragen zu lassen und das Ergebnis im Programm auszugeben ? Ich hab das so verstanden, das ich um in cmd was eintragen zu können, stdin, stdout und stderr = PIPE setzen muss. Und dann ? Ich dachte das get mit communicate, z.B.
Das geht nicht, da "communicate" nicht mit Strings arbeitet :/ ( Was es laut dem Library Eintrag aber müsste
)
Fehlermeldung :Traceback (most recent call last):
File "C:\Python31\Meine scripts\subprocess_cmd2.py", line 6, in <module>
c.communicate('ipconfig/all')
File "C:\Python31\lib\subprocess.py", line 727, in communicate
return self._communicate(input)
File "C:\Python31\lib\subprocess.py", line 937, in _communicate
self.stdin.write(input)
TypeError: must be bytes or buffer, not str
Idiotenfreundiche Hilfe bitte

Wie ich mit dem subprocess modul die Kommandozeile öffne weiß ich.
Code: Alles auswählen
subprocess.Popen('cmd')
Code: Alles auswählen
c = subprocess.Popen('cmd', stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
c.communicate('ipconfig/all')

Fehlermeldung :Traceback (most recent call last):
File "C:\Python31\Meine scripts\subprocess_cmd2.py", line 6, in <module>
c.communicate('ipconfig/all')
File "C:\Python31\lib\subprocess.py", line 727, in communicate
return self._communicate(input)
File "C:\Python31\lib\subprocess.py", line 937, in _communicate
self.stdin.write(input)
TypeError: must be bytes or buffer, not str
Idiotenfreundiche Hilfe bitte
