title: go os/exec command argument issues
body: <p>I wrote some code in Go to call vmstat to pull some statistics data.  There are several variations to the cmdArgs and I annotated which are working and which are not:</p>
  
  <pre><code>1 package main
    2 
    3 import (
    4   "bufio"
    5   "fmt"
    6   "os"
    7   "os/exec"
    8 )
    9 
   10 func main() {
   11   // cmdName := "sar"
   12   // cmdArgs := []string{"-n DEV 1 1"}
   13   cmdName := "vmstat"
   14 
   15   // cmdArgs := []string{"-tSm 1 1"}  //&lt;--- This works but does
   16                                      //     not produce desired output
   17 
   18   cmdArgs := []string{"-t -Sm 1 1"}  //&lt;--- This works but does
   19                                      //     not produce desired output
   20 
   21   // cmdArgs := []string{"-Sm 1 1", "-t"}  //&lt;--- This does NOT work
   22   // cmdArgs := []string{"-t","-Sm 1 1"}   //&lt;--- This does NOT work
   23 
   24   cmd := exec.Command(cmdName, cmdArgs...)
   25   cmdReader, err := cmd.StdoutPipe()
   26   if err != nil {
   27     fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err)
   28     os.Exit(1)
   29   }
   30 
   31   scanner := bufio.NewScanner(cmdReader)
   32   go func() {
   33     for scanner.Scan() {
   34       fmt.Printf("%s\n", scanner.Text())
   35     }
   36   }()
   37 
   38   err = cmd.Start()
   39   if err != nil {
   40     fmt.Fprintln(os.Stderr, "Error starting Cmd", err)
   41     os.Exit(1)
   42   }
   43 
   44   err = cmd.Wait()
   45   if err != nil {
   46     fmt.Fprintln(os.Stderr, "Error waiting for Cmd", err)
   47     os.Exit(1)
   48   }
   49 }
  </code></pre>
  
  <p>Bottom line is I want to get the data in Megabytes and if I run the following on my shell, it works:</p>
  
  <pre><code># vmstat -t -Sm 1 1
  procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---
   r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
   0  1    201   4544    190   7970    0    0    85    32    1    1  1  0 97  2  0    2018-06-21 16:52:13 EDT
  
  # vmstat -Sm -t 1 1
  procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---
   r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
   0  1    201   4496    191   8012    0    0    85    32    1    1  1  0 97  2  0    2018-06-21 16:52:33 EDT
  </code></pre>
  
  <p>My question is  - what is the acceptable way to arrange the arguments and still get the desired output?  Also, I have a similar issue with sar(I am trying to pull network interface stats), but I cannot get it to accept any variation of the arguments:</p>
  
  <pre><code>  1 package main
    2 
    3 import (
    4   "bufio"
    5   "fmt"
    6   "os"
    7   "os/exec"
    8 )
    9 
   10 func main() {
   11   cmdName := "sar"
   12   cmdArgs := []string{"-n DEV 1 1"} //&lt;--- This does NOT work
   13 
   14   // cmdArgs := []string{"-n DEV","1 1"} //&lt;--- This does NOT work
   15 
   16   cmd := exec.Command(cmdName, cmdArgs...)
   17   cmdReader, err := cmd.StdoutPipe()
   18   if err != nil {
   19     fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err)
   20     os.Exit(1)
   21   }
   22 
   23   scanner := bufio.NewScanner(cmdReader)
   24   go func() {
   25     for scanner.Scan() {
   26       fmt.Printf("%s\n", scanner.Text())
   27     }
   28   }()
   29 
   30   err = cmd.Start()
   31   if err != nil {
   32     fmt.Fprintln(os.Stderr, "Error starting Cmd", err)
   33     os.Exit(1)
   34   }
   35 
   36   err = cmd.Wait()
   37   if err != nil {
   38     fmt.Fprintln(os.Stderr, "Error waiting for Cmd", err)
   39     os.Exit(1)
   40   }
   41 }
  </code></pre>
  
  <p>Here is how I call sar from the shell:</p>
  
  <pre><code>$ sar -n DEV 1 1
  Linux 2.6.32-696.18.7.el6.x86_64 (invenioq.gmu.edu)     06/21/2018  _x86_64_    (2 CPU)
  
  05:08:56 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
  05:08:57 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
  05:08:57 PM      eth0      3.96      0.00      0.24      0.00      0.00      0.00      0.00
  05:08:57 PM      eth1      2.97      0.00      0.17      0.00      0.00      0.00      0.00
  
  Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
  Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
  Average:         eth0      3.96      0.00      0.24      0.00      0.00      0.00      0.00
  Average:         eth1      2.97      0.00      0.17      0.00      0.00      0.00      0.00
  </code></pre>
  
  <p>I appreciate any feedback/help.  Thank you</p>