master
Evan Chen 2021-12-10 17:42:47 +08:00
commit cf7b91633e
1 changed files with 34 additions and 0 deletions

34
main.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"fmt"
"os"
"os/exec"
"os/signal"
"time"
)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
file, err := os.OpenFile("out", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(err)
}
file.WriteString("start: " + os.Args[1] + "\n")
for {
select {
case <-c:
file.WriteString("bye\n")
exe, _ := os.Executable()
cmd := exec.Command(exe, os.Args[1:]...)
err := cmd.Start()
if err != nil {
fmt.Println(err)
}
os.Exit(0)
case <-time.Tick(time.Second):
file.WriteString("test\n")
}
}
}