This is a creation in Article, where the information may have evolved or changed.
package mainimport "FMT" import "Io/ioutil" import "Os/exec" Func main () { datecmd := exec. Command ("date") dateout, err := datecmd.output () If err != nil { panic (ERR) } fmt. Println ("> date") fmt. Println (String (dateout)) grepcmd := exec. Command ("grep", "Hello") grepin, _ := grepcmd.stdinpipe () grepout, _ := grepcmd.stdoutpipe () grepcmd.start () grepin.write ([]byte ("Hello grep\ngoodbye grep")) Grepin.close () grepbytes, _ := ioutil. ReadAll (Grepout) grepcmd.wait () fmt. Println ("> grep hello") fmt. Println (String (grepbytes)) lscmd := exec. Command ("bash", "-C", "Ls -a -l -h") lsout, err := lscmd.output () if err != nil { panic (Err) } fmt. Println ("> ls -a -l -h") fmt. Println (String (lsout))}
Execution Result:
> date2015 January 23 Friday 21:29 39 seconds cst> grep hellohello grep> ls-a-l-htotal 32drwxr-xr-x 6 ITFANR admin 204B 1 21:29. drwxrwxrwx 6 ITFANR Admin 204B 12 27 09:52.. -rw-rw-r--@ 1 Itfanr Admin 721B 1 21:29 excute.godrwxr-xr-x itfanr admin 442B 1 21:06 github.com
Reference:
Https://gobyexample.com/spawning-processes
Http://tobegit3hub1.gitbooks.io/understanding-linux-processes/content/go_example/spawn.html
3. Https://github.com/mmcgrana/gobyexample