dongpo4197
2014-04-28 19:26 阅读 88
已采纳

在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 {
            fmt.Println(sig.String())
        }
        }()

        time.Sleep(5000 * time.Millisecond) 
        fmt.Println("Done")
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    draxq02664 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.

    点赞 评论 复制链接分享

相关推荐