【问题标题】:Communicating to a process launched in the Terminal in UNIX through python通过 python 与 UNIX 终端中启动的进程通信
【发布时间】:2016-11-15 16:12:41
【问题描述】:

我正在创建一个 GUI 来简化 UNIX 中的一些任务。 我想在 UNIX 中通过终端启动一个进程。 我使用了

的模块
subprocess.Popen()

启动进程。 问题是,当我启动该进程时,该进程要求用户输入他们的密码。 我正在考虑创建一个窗口来询问用户的密码。 如何将在窗口中输入的密码发送到终端中的进程启动?

代码如下:

password = wx.TextEntryDialog(None, "What is your password?", 'Password')
    if password.ShowModal() == wx.ID_OK:
        response = password.GetValue()

        command = 'ssh -X pcalcul0 firefox http://qualnetsrv/intraqual//identification.aspx?ref=G0-1427'
        user_manual = subprocess.Popen(command, universal_newlines=True, 
                                       stdin=response,
                                       stdout=subprocess.PIPE, 
                                       stderr=subprocess.STDOUT,
                                       shell=True)

【问题讨论】:

    标签: python wxpython subprocess


    【解决方案1】:

    您应该可以使用Pexpect 包来执行此类操作。它已在其他答案中进行了详细说明,例如这个:

    或者,您可以创建一些 SSH 密钥,以便它自动登录。

    我知道的另一种方法是使用Paramiko。然后你可以使用 Python 本身来做你需要的 SSH / SCP。

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 2012-06-03
      • 2018-01-26
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 2018-01-11
      相关资源
      最近更新 更多