I've read through my post again. I'll try to simplify my question: Where is stdout for a Windows "GUI binary"? (see -H option)
https://pkg.go.dev/cmd/link If I run from the command prompt I would have thought that stdout is the console I'm running from but if the executable is a "GUI binary" this does not seem to be the case. If I create a "console binary" then stdout is indeed the console I'm running from. But this means that when I run the binary from a desktop icon, Windows will open up a console window, even if there is nothing to output. Context for this is an application that has a GUI by default and optionally, a terminal interface (using stdout). I'm not a Windows person and I'm sorry if this is a dumb question but this is a complete mystery to me. Do I really need two separate binaries? On Monday, April 25, 2022 at 9:48:18 AM UTC+1 stephen.t....@gmail.com wrote: > Hello, > > I'm cross-compiling my Go application to Windows and I'm having difficulty > understanding how Windows interacts with stdout. > > I'm compiling the Windows binary with the "-H=windowsgui" LD flag. This > works great but I've found that the program will never print to stdout, > even if the program is launched from the command prompt > > The alternative LD flag "-H=windows" will print to stdout but with the > downside that a "DOS" window will always open, even if the program is > launched from the desktop icon and even when there is no stdout activity. > > For the most part, compiling with "-H=windowsgui" is fine but occasionally > it's useful for users to run with the program's -log option, which outputs > to stdout. > > My solution for now is to have two Windows binaries. One for regular use > and another for diagnosing problems. This is a poor solution. > > What I require is a single binary that can: > > 1) Launch from the desktop icon without a "DOS" window opening. > 2) To launch from a command prompt and for stdout to be echoed to the > command prompt window. > > Is there a Go compilation option that I've missed. Or is the solution more > complex? > > Regards > > Stephen > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/84d95a6c-441e-4b83-b1e2-abc59838bf7cn%40googlegroups.com.