我有一个小程序(程序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'的任何输入的代码。 –