title: Why am I losing portions of my command line arguments? PHP/shell_exec
body: <p>I have a PHP script that takes data that is a 'JSON ready' string and passes that through a command line via shell_exec to the Windows OS command line. On the other end (which is a python script) I gather the argument via sys.argv and for debugging purposes I print the argument to a simple .txt file. When I inspect the file I notice that roughly the last half of my argument from the PHP script is missing. I initially thought after doing some digging that perhaps I was exceeding some sort of character limit either in PHP shell_exec's function or the command line itself. My research came to this page from Microsoft: <a href="https://docs.microsoft.com/en-US/troubleshoot/windows-client/shell-experience/command-line-string-limitation" rel="nofollow noreferrer">Command prompt (Cmd. exe) command-line string limitation</a> that states the command line has a character limit of 2047 characters.</p>
  <p>I was hopeful that this was going to be my problem as I could work around it but unfortunately my command string only has 1730 characters total.</p>
  <p>I know I can either chunk the arguments and send the chunks individually over, or save the argument as a file and have my python script pick it up that way, but if I am within the operating parameters of the command line, in a sense that this 'should' work then I'd prefer to utilize this method. Not to mention that I am working in a windows environment now for our Dev version of our application but production gets pushed to a Linux server (I hate this but unfortunately I don't have control of these factors). And on our production Linux distribution it works and utilizes this command line processes.</p>
  <p>Here is my command line code:</p>
  <pre><code>$cmd = &quot;python C:\\xampp\\htdocs\\app\\pages\\plot\\python\\plotfunction.py &quot; .$data;
  $output = shell_exec($cmd .' 2&gt;&amp;1 &amp;');
  </code></pre>
  <p>And $data is a json-like string that contains 1653 characters.</p>
  <p>The python that reads the sys.argv is this:</p>
  <pre><code>ATP_CHART_SPEC_json = sys.argv[1].replace(&quot;$&quot;, '&quot;')
  </code></pre>
  <p>And when I save ATP_CHART_SPEC_json to a file it contains only 750 characters. I'm losing a little more than half of my argument.</p>
  <p>NOTE:</p>
  <p>The .replace in python was used by me to overcome the issue that apparently when sending a string as an argument over the command line (or for some other reason I am not aware of) I lose all of my '&quot;' characters which when they're escaped using &quot;&quot; in python becomes a problem. So temporarily in PHP I replace all quotes with $ and replace them back after the transfer. I've verified this does not (usually) damage the integrity of the JSON string.</p>