2014-04-28 19:26
浏览 109

在Cygwin上捕捉Ctrl + c

The following golang code catches CTRL+C when run from a DOS prompt, but when I run it from Cygwin it doesn't catch anything when CTRL+C is pressed.

What does Cygwin do when CTRL+C 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 {

        time.Sleep(5000 * time.Millisecond) 

图片转代码服务由CSDN问答提供 功能建议

以下golang代码在运行时捕获 CTRL + C 从DOS提示符下输入,但是当我从Cygwin运行它时,按 CTRL + C 时它什么也没捕获。

当按 CTRL + C 时,Cygwin会做什么? 我的操作系统是Win32 64位,运行32位Cygwin。

  func main(){
c:= make(chan os.Signal,1)
 signal.Notify(c  ,os.Interrupt)
 for sig:= range c {
 time.Sleep(5000  * time.Millisecond)
 fmt.Println(“ Done”)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • draxq02664 2014-05-01 00:46

    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 CTRL+C in a golang program launched from Cygwin.

    点赞 评论

相关推荐 更多相似问题