Go derivative (Spawn) New process

Source: Internet
Author: User
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:

    1. Https://gobyexample.com/spawning-processes

    2. Http://tobegit3hub1.gitbooks.io/understanding-linux-processes/content/go_example/spawn.html

3. Https://github.com/mmcgrana/gobyexample


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.