运行一个指令,并在几秒后中止它。
package main
import (
"fmt"
"os/exec"
"time"
"syscall"
)
func main() {
cmd := exec.Command("arecord", "1.wav")
start := time.Now()
time.AfterFunc(10*time.Second, func() {
//cmd.Process.Kill()
cmd.Process.Signal(syscall.SIGINT)
})
err := cmd.Run()
fmt.Printf("pid=%d duration=%s err=%s\n", cmd.Process.Pid, time.Since(start), err)
}