title: How to pipe several commands in Go?
body: <p>How can I pipe several external commands together in Go? I've tried this code but I get an error that says <code>exit status 1</code>.</p>
  
  <pre><code>package main
  
  import (
      "io"
      "log"
      "os"
      "os/exec"
  )
  
  func main() {
      c1 := exec.Command("ls")
      stdout1, err := c1.StdoutPipe()
      if err != nil {
          log.Fatal(err)
      }
  
      if err = c1.Start(); err != nil {
          log.Fatal(err)
      }
      if err = c1.Wait(); err != nil {
          log.Fatal(err)
      }
  
      c2 := exec.Command("wc", "-l")
      c2.Stdin = stdout1
  
      stdout2, err := c2.StdoutPipe()
      if err != nil {
          log.Fatal(err)
      }
  
      if err = c2.Start(); err != nil {
          log.Fatal(err)
      }
      if err = c2.Wait(); err != nil {
          log.Fatal(err)
      }
  
      io.Copy(os.Stdout, stdout2)
  }
  </code></pre>