golang 使用编译选项-H=windowsgui后,仍然输出log到console
大概原理:
略略略。。。
if debug {
modkernel32 := syscall.NewLazyDLL("kernel32.dll")
procAllocConsole := modkernel32.NewProc("AllocConsole")
r0, _, err0 := syscall.Syscall(procAllocConsole.Addr(), 0, 0, 0, 0)
if r0 == 0 {
fmt.Printf("Could not allocate console: %s. Check build flags..", err0)
os.Exit(1)
}
hout, err1 := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
if err1 != nil {
os.Exit(2)
}
os.Stdout = os.NewFile(uintptr(hout), "/dev/stdout")
}
参考链接: stackoverflow.com
浙公网安备 33010602011771号