Catching Ctrl+c on cygwin

huangapple go评论85阅读模式
英文:

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(&quot;Done&quot;)
    }

答案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.

huangapple
  • 本文由 发表于 2014年4月29日 03:26:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/23349556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定