関連する質問で、C 関数「待機」のドキュメントがどこにあるかを尋ねました。これは、commands.getstatusoutput() モジュールのリターン コードを把握するための試みでした。Stackoverflow は成功しましたが、ドキュメントは役に立ちませんでした。これが私を困惑させるものです:
#!/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)
OS X (Leopard) で実行すると、次の出力が得られます: (これはドキュメントと一致します。)
$ python waitest.py
Good command reported status of 0
Bad command reported status of 256
OS X では、「ls /fail ; echo $?」を実行します。次の出力を取得します。
$ ls /fail ; echo $?
ls: /fail: No such file or directory
1
Linux (Ubuntu Hardy) で実行すると、次の出力が得られます。
$ python waitest.py
Good command reported status of 0
Bad command reported status of 512
Ubuntu では、「ls /fail」を実行すると 2 が返されます。
$ ls /fail ; echo $?
ls: cannot access /fail: No such file or directory
2
つまり、Python はステータス コードを 256 倍しているように見えます。これはどこかに文書化されていますか?