GoLang – How to Execute/Spawn a process as 'Hidden'

huangapple go评论103阅读模式
英文:

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

huangapple
  • 本文由 发表于 2013年11月11日 22:27:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/19908735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定