title: C++, is it possible (and how) to run a multi-action, one-liner curl command via exec()?
body: <p>I have a curl command:</p>
  
  <pre><code>curl -c cookies.txt -b cookies.txt -k https://www.example.com/ajaxauth/login -d 'identity=email@example.com&amp;password=pa$$w0rd&amp;query=https://example.com/data/format/json' &gt; ~/Documents/.../myProject/bin/data/myData.json"
  </code></pre>
  
  <p>that</p>
  
  <ol>
  <li>logs in to an API,</li>
  <li>manages cookies, </li>
  <li>fetches a dataset and saves to local file.</li>
  </ol>
  
  <p>I have it in a char array and was sending to the <code>system()</code> command, but due to the dangers of passing vars (email and password) to <code>system()</code>, I must use <code>exec()</code> instead. I'm not familiar with this command and the documentation is confusing me. So my questions: </p>
  
  <ul>
  <li><p>Is this even possible or do I <em>have</em> to go back and break up my command into individual calls or even multiple exec calls?</p></li>
  <li><p>I assume I should be using an exec<strong>v</strong> version because I'm passing in a whole character array, is this correct?</p></li>
  <li><p>Many different sources say the first argument for an <code>exec()</code> command must be an executable file. <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/execl.3.html" rel="nofollow noreferrer">For example</a>, "The first argument, by convention, should point to the file name associated with the file being executed." How does a curl command count as such? </p></li>
  <li><p>Why is <a href="https://stackoverflow.com/q/5631229/1757149">this person</a> passing <code>(char *) 0</code> as the last argument? </p></li>
  </ul>
  
  <p>This is what I have so far:</p>
  
  <pre><code>int pid = fork();
  
  switch(pid){
      case -1:{            
          perror("fork"); // via https://stackoverflow.com/q/2329640/1757149
          _exit(EXIT_FAILURE);
          break;
      }
      case 0:{ // child process
          //execv(cmd, ???);
          break;
      }
      default:{ // parent process                
          break;
      }
  }
  </code></pre>
  
  <p>Note that I can't use libcurl. Any help appreciated!</p>