In einem related question fragte ich, wo die Dokumentation für die C-Funktion "wait" zu finden ist. Dies war ein Versuch, Rückgabecodes für das commands.getstatusoutput() Modul herauszufinden. Stackoverflow kam durch, aber die Dokumentation half nicht. Hier ist, was mir ein Rätsel:Wie interpretiere ich den Statuscode in Python? Commands.getstatusoutput()
#!/usr/bin/python
import commands
goodcommand = 'ls /'
badcommand = 'ls /fail'
status, output = commands.getstatusoutput(goodcommand)
print('Good command reported status of %s' % status)
status, output = commands.getstatusoutput(badcommand)
print('Bad command reported status of %s' % status)
Wenn auf OS X (Leopard) laufen bekomme ich folgende Ausgabe: (. Welche der Dokumentation übereinstimmt)
$ python waitest.py
Good command reported status of 0
Bad command reported status of 256
Unter OS X eine „ls/tun scheitern ; echo $? " die folgende Ausgabe erhält:
$ ls /fail ; echo $?
ls: /fail: No such file or directory
1
Wenn auf Linux (Ubuntu Hardy) betreibe ich folgende Ausgabe:
$ python waitest.py
Good command reported status of 0
Bad command reported status of 512
Unter Ubuntu tun "ls/fail" erhält einen 2:
$ ls /fail ; echo $?
ls: cannot access /fail: No such file or directory
2
Also Python scheint Statuscodes mit 256 zu multiplizieren. Huh? Ist das irgendwo dokumentiert?
die [Antwort von @Schof] (http://stackoverflow.com/a/1535675/52074) beantwortet die Frage „sein sollte, wenn mit' commands.getstatusoutput() 'Warum werden die Exitcodes mit 256 multipliziert?" direkt und mit Beispielcode. Die anderen beiden Antworten sagen mehr oder weniger "subprocess verwenden" anstelle von "commands.getstatusoutput()' "oder" hier ist wie Subprozess zu verwenden ". –