title: How to execute system command with unknown arguments?
body: <p>I have a bunch of systems commands which are somwhat similar to appending new content to a file. I wrote a simple script to execute system commands, which works well if there are single words like 'ls' , 'date' etc. But if the command is greater than that, program dies.</p>
  <p>The following is the code</p>
  <pre><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;os/exec&quot;
      &quot;sync&quot;
  )
  
  func exe_cmd(cmd string, wg *sync.WaitGroup) {
      fmt.Println(cmd)
      c = cmd.Str
      out, err := exec.Command(cmd).Output()
      if err != nil {
          fmt.Println(&quot;error occured&quot;)
          fmt.Printf(&quot;%s&quot;, err)
      }
      fmt.Printf(&quot;%s&quot;, out)
      wg.Done()
  }
  
  func main() {
      wg := new(sync.WaitGroup)
      wg.Add(3)
  
      x := []string{&quot;echo newline &gt;&gt; foo.o&quot;, &quot;echo newline &gt;&gt; f1.o&quot;, &quot;echo newline &gt;&gt; f2.o&quot;}
      go exe_cmd(x[0], wg)
      go exe_cmd(x[1], wg)
      go exe_cmd(x[2], wg)
  
      wg.Wait()
  }
  </code></pre>
  <p>The following is the error i see</p>
  <pre><code>exec: &quot;echo newline &gt;&gt; foo.o&quot;: executable file not found in $PATHexec: 
  &quot;echo newline &gt;&gt; f2.o&quot;: executable file not found in $PATHexec: 
  &quot;echo newline &gt;&gt; f1.o&quot;: executable file not found in $PATH 
  </code></pre>
  <p>I guess, this may be due to, not sending cmds and arguments seperately ( <a href="http://golang.org/pkg/os/exec/#Command" rel="nofollow noreferrer">http://golang.org/pkg/os/exec/#Command</a> ). I am wondering how to subvert this, since I don't know how many arguments will be there in my command which needs to be executed.</p>