英文:
GoLang - How to Execute/Spawn a process as 'Hidden'
问题
这可能只适用于Windows,但我想从我的GO程序中生成一个进程,使其在后台运行 - 该进程将计算一些结果并通过stdout返回。我只是不希望在运行过程中弹出烦人的命令窗口(它实际上只是一个后台计算进程)。
如何执行另一个“隐藏”的进程?
谢谢!
英文:
This may only pertain to Windows, but I want to spawn a process from my GO program so that it runs hidden - the process will calculate some results and return them over stdout. I just don't want the annoying command window to popup while it is running (it's really just a background calculation process).
How can you execute another process 'hidden'?
Thanks!
答案1
得分: 5
尝试像这样使用:
var attr os.ProcAttr
attr.Sys.HideWindow = true
p, err := os.StartProcess("whatever", nil, &attr)
这会在Windows中设置STARTF_USESHOWWINDOW
标志,应该可以阻止被调用的进程打开一个命令行窗口。
请参阅Microsoft文档。
英文:
Try something like this
var attr os.ProcAttr
attr.Sys.HideWindow = true
p, err := os.StartProcess("whatever", nil, &attr)
That sets the STARTF_USESHOWWINDOW
flag in windows which should stop the called process opening up a cmd window.
See the Microsoft documentation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论