Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用了这么,终于可以提一个 Bug 了 #253

Open
forcemeter opened this issue Aug 2, 2020 · 6 comments
Open

用了这么,终于可以提一个 Bug 了 #253

forcemeter opened this issue Aug 2, 2020 · 6 comments

Comments

@forcemeter
Copy link

工具很好,一直也想参与做点贡献,终于等到这一天了。

在 Winddows 上,如果使用 Debug = true 并同时开启编译参数 -ldflags "-H windowsgui",则会抛出如下异常

write /dev/stdout: The handle is invalid.

因为这个 bug 折腾了两个小时,好不容易定位原因了,也算做出一点贡献了。我的解决办法是在 Windows 下,Debug 直接关闭就好了。

@guonaihong
Copy link
Owner

感谢。我最近会修复下。

@guonaihong
Copy link
Owner

最近一周有点忙,15号之后有时间修复。或者 @botsphp 也可以提pr,合作修复。

@forcemeter
Copy link
Author

@guonaihong 我试试吧,我不太清楚如何在 Windows 下,识别windowsgui的状态,初步的想法是捕获这个异常,不影响使用即可。

@xzhanjob
Copy link

xzhanjob commented Nov 1, 2020

@botsphp 原谅我不厚道的笑了

@forcemeter
Copy link
Author

@botsphp 原谅我不厚道的笑了

比如?

@guonaihong
Copy link
Owner

这个现象分析了下,go里面的打印函数只能向终端输出日志,gui的环境输出会报错。

在windows gui输出日志,我这边找到一个方法。你看下面的代码可以在你的windows gui里面输出信息不? @botsphp

        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")
        os.Stdout.Write("hello word")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants