os.system() コマンドを使用してリモート サーバー (ssh) にシェル コマンドを発行するスクリプトを使用しています。リモート サーバーで実行したコマンドの出力を収集する必要があります。問題は二重リダイレクトです。os.system() を使用して、リモート サーバーで目的のコマンドを実行する ssh コマンドを実行しています。私が利用したいのはこのアウトプットです。これをどのように達成できるかについての指針が必要ですか?
質問する
261 次
1 に答える
3
subprocess
モジュールを使用します。
subprocess.check_output
コマンドの出力を文字列として返します。
>>> import subprocess
>>> print subprocess.check_output.__doc__
Run command with arguments and return its output as a byte string.
If the exit code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
attribute and output in the output attribute.
于 2013-07-08T18:14:59.813 に答える