It should be doable with just go code and the windows package.. CreateFile can do the same work that freopen is doing.
The *CreateFile* <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea> function enables a process to get a handle to its console's input buffer and active screen buffer, even if STDIN and STDOUT have been redirected. To open a handle to a console's input buffer, specify the CONIN$ value in a call to *CreateFile*. Specify the CONOUT$ value in a call to *CreateFile* to open a handle to a console's active screen buffer. *CreateFile* enables you to specify the read/write access of the handle that it return. On Thursday, May 5, 2022 at 1:56:43 AM UTC-4 stephen.t....@gmail.com wrote: > The blog is very interesting. However, I can't see how to re-implement > this in Go with only the syscall package or the golang.org/x/sys/windows > package. It needs the functionality of C++ freopen(), which as far as I can > tell is not possible with the WinAPI - From what I can gather, ReOpen() > only works with file handles and not console handles returned by > GetStdHandle(). > > On Monday, May 2, 2022 at 2:34:03 PM UTC+1: > >> >> https://www.tillett.info/2013/05/13/how-to-create-a-windows-program-that-works-as-both-as-a-gui-and-console-application/ >> >> -- 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/a32a24f0-fa45-44e9-b364-ac5fdc73620cn%40googlegroups.com.