【问题标题】:loading another program that takes in a textfile in a program subprocess在程序子进程中加载​​另一个接收文本文件的程序
【发布时间】:2012-11-22 14:02:16
【问题描述】:

我想将另一个程序加载到我的 python GUI 中。 另一个程序接收一个文本文件并打印出一个结果 我想在我的其他程序中打印结果 我只是想知道如何使用 subprocess 模块来解决这个问题

这是正确的做法吗?

def test(self,event):
    t=subprocess.check_output("filename test.py", shell=True)
    wx.StaticText(self,-1,t, (10,35))

谢谢

【问题讨论】:

  • 虽然check_output() 可用于获取子进程的输出;在这种情况下,您可能不需要子流程。您可以只 import test 并在其中调用适当的函数。
  • 对我来说似乎没问题 - 不工作吗?

标签: python user-interface wxpython subprocess


【解决方案1】:

通过子进程获取命令输出的方法是check_output function:

cmd = 'ping 192.168.1.1'
output = subprocess.check_output(cmd.split())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 2012-03-13
    相关资源
    最近更新 更多