开发者

How to add input to command line prompt from wxPython?

So I have this code on python, that retrieves output from console when executing shell commands.

def OnClick(self, event):
    cmd = self.command.GetValue()
    if cmd:
        input, output, errors = os.popen3(cmd)
        errors = errors.read()
    if errors:
        dlg = wx.MessageDialog(self, errors,
        'An error occurred',
        wx.OK | wx.ICON_EXCLAMATION)
        dlg.ShowModal()
        self.output.SetValue('')
    else:
        self.ou开发者_运维百科tput.SetValue(output.read())

This works well in simple prints, but I have a password prompt on console, that I'd like to interact from wxPython. Is it possible and how would you do it in this scenario?


Typically when you have a long running process, you need to use a thread. See wiki.wxpython.org/LongRunningTasks for several example solutions. When you get to the password prompt, you can send some kind of notification to the GUI to display a dialog using wx.CallAfter or wx.PostEvent. There are ways to communicate with a thread, but I'll leave you to Google for that as it's beyond the scope of a simple answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜