Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fd0
Created January 17, 2018 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fd0/5eff1b82dfa79f72a87ce86444899d3e to your computer and use it in GitHub Desktop.
Save fd0/5eff1b82dfa79f72a87ce86444899d3e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"os/exec"
"os/signal"
"syscall"
)
func main() {
cmd := exec.Command("ssh", "localhost", "echo 'remote: start'; sleep 60; echo 'remote: done'")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT)
go func() {
for sig := range ch {
fmt.Printf("main: signal received: %v\n", sig)
}
}()
signal.Ignore(syscall.SIGINT)
err := cmd.Start()
if err != nil {
fmt.Printf("main: start returned err: %v\n", err)
}
signal.Notify(ch, syscall.SIGINT)
err = cmd.Wait()
if err != nil {
fmt.Printf("main: wait returned err: %v\n", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment