利用可能な条件: Unix.
commandsは、システムへコマンド文字列を渡して実行する os.popen()のラッパー関数を含んでいるモジュールです。 外部で実行したコマンドの結果や、その終了ステータスを扱います。
commandsモジュールは以下の関数を定義しています。
| cmd) |
(status, output)を返します。
実際には{ cmd ; } 2>&1と実行されるため、
標準出力とエラー出力が混合されます。
また、出力の最後の改行文字は取り除かれます。
コマンドの終了ステータスはC言語関数のwait()の規則に従って
解釈することができます。
| cmd) |
| file) |
例:
>>> import commands
>>> commands.getstatusoutput('ls /bin/ls')
(0, '/bin/ls')
>>> commands.getstatusoutput('cat /bin/junk')
(256, 'cat: /bin/junk: No such file or directory')
>>> commands.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found')
>>> commands.getoutput('ls /bin/ls')
'/bin/ls'
>>> commands.getstatus('/bin/ls')
'-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls'
ご意見やご指摘をお寄せになりたい方は、 このドキュメントについて... をご覧ください。