如何在 Python 中静默运行控制台应用程序(在 Windows 上)
嗨,
在我的应用程序中,我正在使用外部控制台应用程序。 我正在捕获它的输出(从标准输出)并处理它。但每次我启动这个应用程序时,控制台窗口都会弹出,这是一个问题(因为在计算过程中我无法使用计算机进行任何其他操作)。有没有办法执行控制台应用程序,捕获其标准输出而不实际弹出控制台窗口? 正在执行控制台应用程序的代码:
p = subprocess.Popen([BCALCPATH, "-c", hand, "-t", "a", "-e", "e", "-q", "-d SWNE"], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
table = p.stdout.read().decode()
所有这些 -c、-t 等都是控制台应用程序的参数。 BCALCPATH 是 .exe 文件的路径。 感谢您的帮助:)
Possible Duplicate:
How do I eliminate Windows consoles from spawned processes in Python (2.7)?
Hi,
In my application I am using external console application.
I am catching its output (from std out) and process it. What is happening though that every time I start this application the console window is popping out which is a problem (because I can't use the computer for anything else during the calculations). Is there any way to execute console application, catch its stdout without actually having console window to pop up?
The code which is executing the console app:
p = subprocess.Popen([BCALCPATH, "-c", hand, "-t", "a", "-e", "e", "-q", "-d SWNE"], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
table = p.stdout.read().decode()
All those -c, -t etc. are argument for the console app. BCALCPATH is path to the .exe file.
Thanks for help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建 Python 脚本的 Windows 快捷方式,然后将快捷方式的
Run
属性设置为Minimized
。Create a Windows shortcut to the Python script and then set the shortcut's
Run
property toMinimized
.您可以尝试使用 hstart 之类的实用程序。不过,您可能必须将输出重定向到文件,然后在命令完成后从中读取。 Cygwin 有一个类似的工具,名为
run.exe
(如果您手头有的话)。You could try using a utility like hstart. You might have to redirect the output to a file and then read from that after the command finishes, though. Cygwin has a similar tool called
run.exe
if you have that on hand.