...
1 package main
2
3 import (
4 "fmt"
5 "time"
6
7 sh "github.com/codeskyblue/go-sh"
8 )
9
10 func main() {
11 c := sh.Command("sleep", "3")
12 c.Start()
13 err := c.WaitTimeout(time.Second * 1)
14 if err != nil {
15 fmt.Printf("timeout should happend: %v\n", err)
16 }
17
18 out, err := sh.Command("sleep", "2").SetTimeout(time.Second).Output()
19 fmt.Printf("output:(%s), err(%v)\n", string(out), err)
20
21 out, err = sh.Command("echo", "hello").SetTimeout(time.Second).Output()
22 fmt.Printf("output:(%s), err(%v)\n", string(out), err)
23 }
24
View as plain text