英文:
Catching Ctrl+c on cygwin
问题
以下是翻译好的内容:
下面的golang代码在从DOS提示符运行时捕获<kbd>CTRL</kbd>+<kbd>C</kbd>,但在从Cygwin运行时,当按下<kbd>CTRL</kbd>+<kbd>C</kbd>时它不会捕获任何内容。
当按下<kbd>CTRL</kbd>+<kbd>C</kbd>时,Cygwin会做什么?我的操作系统是运行32位Cygwin的Win7 64位。
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func(){
for sig := range c {
fmt.Println(sig.String())
}
}()
time.Sleep(5000 * time.Millisecond)
fmt.Println("Done")
}
英文:
The following golang code catches <kbd>CTRL</kbd>+<kbd>C</kbd> when run from a DOS prompt, but when I run it from Cygwin it doesn't catch anything when <kbd>CTRL</kbd>+<kbd>C</kbd> is pressed.
What does Cygwin do when <kbd>CTRL</kbd>+<kbd>C</kbd> is pressed? My OS is Win7 64 bit running 32 bit Cygwin.
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func(){
for sig := range c {
fmt.Println(sig.String())
}
}()
time.Sleep(5000 * time.Millisecond)
fmt.Println("Done")
}
答案1
得分: 5
我在cygwin邮件列表上得到的答案是,为了使信号传递工作,程序必须使用Cygwin编译器和链接器进行编译和链接。Cygwin不是golang的支持平台,所以我无法在从Cygwin启动的golang程序中捕获Ctrl+C。
英文:
The answer I got on the cygwin mail list is that in order for signaling to work the program has to be compiled and linked with a Cygwin compiler and linker. Cygwin is not a supported platform for golang, so I'm not going to be able to catch <kbd>CTRL</kbd>+<kbd>C</kbd> in a golang program launched from Cygwin.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论