0
私はサブプロセス端子とインタラクティブにしたいとパスワードを送信するが、私はどのstdout
を得ることができなかったことに気づいた場合、私はsudo
とssh
とインタラクティブではないので、どのように解決する可能性を意味し、いくつかのプログラム呼び出しgetpass(prompt)
(http://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/getpass.html)パスワードを入力するときに、Pythonサブプロセスモジュールがstdoutをリダイレクトできませんでしたか?
この問題?ありがとう。ここで
は一例です:
process = subprocess.Popen(['sudo', 'apt', 'update'],
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
while True:
# prefix '>>' in parent process
# but we could see the stdout without prefix, that means read() never return
# the subprocess just ignored the redirect of stdout
print('>>', process.stdout.read())
time.sleep(1)
あなたの答えをありがとう、上のコードは単なる例です。コードを実行すると、接頭辞なしの何かが表示されます。つまり、read()は返されません(サブプロセスはstdoutのリダイレクトを無視します)。私はsbuprocessのステータスを確認することはできません。何かアドバイス? – hfawja
このコードを使用しましたか? Uは画面上の出力を見ることができます.testoutputは全てのstdoutを含み、印刷されます。 –
さて、解決策を見つけました。返信いただきありがとうございます。https://stackoverflow.com/questions/27933592/capturing-all-terminal-output-of-a-program-called-from-python – hfawja