title: exec.Command Escaping Variables with JSON Payload
body: <p>Thank you in advance as I have spent 2 days on this. Here is a working curl command.</p>
  
  <pre><code>curl -ku login:pass -X POST -H 'Content-Type: application/json'-d'{"type":"page","title":"Testpage","space":{"key":"ITDept"},"body":{"storage":{"value":"&lt;p&gt;Blank Page.&lt;/p&gt;","representation":"storage"}}}' https://confluence/rest/api/content
  </code></pre>
  
  <p>I need to get this to execute with exec.Command. </p>
  
  <p>Given that now in Go I have tried escaping and all sorts of other means to get this to work.  The issue is more than likely this ridiculous JSON string that is required.  I have the JSON string saved into a var now to try it that way.</p>
  
  <pre><code>jsonPayload := '{"type":"page","title":"Testpage","space":{"key":"ITDept"},"body":{"storage":{"value":"&lt;p&gt;Blank Page.&lt;/p&gt;","representation":"storage"}}}'
  
  execCmd := "bash", "-c", "curl -ku login:pass -X POST -H 'Content-Type: application/json' -d" jsonPayload "https://confluence/rest/api/content"
  </code></pre>
  
  <p>So the jsonPayload is the argument to -d.  I have tried this using the Marshal json/encoding and the net/http package and it goes through but something about how that stdlib is sending it causes the API to state it is the wrong format.</p>
  
  <p>I also have tried this with this and the curl copied out of the println works but when actually ran in golang it fails with incorrect format.</p>
  
  <pre><code>    env := os.Environ()
      curlCmd, err := exec.LookPath("curl")
      if err != nil {
          fmt.Println("Path not found to binary!")
          panic(err)
      }
  args := []string{"curl", "-ku", "login:pass", "-X", "POST", "-H", "'Content-Type: application/json'", "-d", payloadJson, "https://confluence/rest/api/content"}
  
  execErr := syscall.Exec(curlcmd, args, env)
     if execErr != nil {
        panic(execErr)
  }
  fmt.Println(curlCmd)
  </code></pre>
  
  <p>When the curlCmd from that last line there prints it can be copied and pasted into the terminal and it works however when going through golang it comes with a format not supported.  Any help would be greatly appreciated.</p>