我有一個小程序(程序A)要求輸入密碼,如果密碼正確,它會打開一個shell。我想在python中創建另一個程序(程序B),它調用程序A並給出密碼作爲輸入,以便打開shell。使用子進程的Python利用
我正在做以下工作,但程序只是終止,不讓我使用shell。
p = subprocess.Popen("./ProgramA", stdin=subprocess.PIPE)
p.communicate("password")
當運行程序B我的終端是這樣的:
~/Desktop/$./ProgramB
Password: Here is your shell.
~/Desktop/$ (this is not the shell opened by program A)
我該如何解決這個問題?
這也不會使它工作,因爲用戶無法提供任何交互式輸入到shell。您需要添加將'ProgramB'的標準輸入轉發給'ProgramA'的任何輸入的代碼。 –