我什至不知道 PhantomJS 是什么,但如果它是可执行文件,这可能会有所帮助。
我通过使用 subprocess.Popen 从 wxPython 应用程序管道到 ffmpeg 并设置 shell 和 creationflags 选项。然后我看不到 ffmpeg 的控制台。
import subprocess
from win32process import CREATE_NO_WINDOW
p = subprocess.Popen(
cmdstring,
stdin=subprocess.PIPE,
bufsize=-1,
shell=False,
creationflags = CREATE_NO_WINDOW
)
(编辑)
就像你写的那样,这里有两个问题。一个是关于 UAC,这可能很难完全解决,如https://stackoverflow.com/a/131092/566035 所述。但是因为无论如何你都是用 py2exe 打包的,你可以试试这个 py2exe 打包选项:https://stackoverflow.com/a/1445547/566035。
windows = [{
'script': "yourapp.py",
'uac_info': "requireAdministrator",
},]
这一行转到py2exe的setup.py文件来打包你的应用程序。
使用这种方法,用户在启动 wxpython 应用程序时只会被要求提供一次 UAC 权限。 UAC 会说您的应用程序正在请求权限(而不是 PhantomJS)。
另一个是控制台窗口,如上所述,它可以被 CREATE_NO_WINDOW 抑制。为了更完整,我添加了一个来自http://phantomjs.org/quick-start.html的示例
phantomjs loadspeed.js http://www.google.com
要从 wxpython 应用程序执行此命令,例如可以编写 wx.Frame 的方法,例如:
def OnButton(self, event):
cmdstring = ('phantomjs.exe', 'loadspeed.js', 'http://www.google.com')
p = subprocess.Popen(
cmdstring,
stdout=subprocess.PIPE,
shell=False,
creationflags = CREATE_NO_WINDOW
)
print p.stdout.read() # to get the output from phantomjs.exe
phantomjs.exe 和 loadspeed.js 需要在系统路径或者同一个文件夹。
我在我的电脑上做了一个测试,它把它打印为输出。
Loading time 719 msec