Printing output to a command window when golang application is compiled with -ldflags -H=windowsgui

后端 未结 5 1762
野性不改
野性不改 2021-02-05 14:09

I have an application that usually runs silent in the background, so I compile it with

go build -ldflags -H=windowsgui 

To check

5条回答
  •  别那么骄傲
    2021-02-05 14:33

    If you build a windowless app you can get output with PowerShell command Out-String

    .\\main.exe | out-string
    

    your build command may look like:

    cls; go build -i -ldflags -H=windowsgui main.go; .\\main.exe | out-string;
    

    or

    cls; go run -ldflags -H=windowsgui main.go | out-string
    

    No tricky syscalls nor kernel DLLs needed!

提交回复
热议问题