O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

The following steps cover the solution:

  1. Open the console and create the folder chapter01/recipe08.
  2. Navigate to the directory.
  3. Create the run.go file with the following content:
        package main        import (          "bytes"          "fmt"          "os/exec"        )        func main() {          prc := exec.Command("ls", "-a")          out := bytes.NewBuffer([]byte{})          prc.Stdout = out          err := prc.Run()          if err != nil {            fmt.Println(err)          }          if prc.ProcessState.Success() {            fmt.Println("Process run successfully with output:\n")            fmt.Println(out.String())          }        }
  1. Run the code by executing go run run.go.
  1. See the output in the Terminal:
  1. Create the start.go file with the following content:
 package ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required