title: How to pass the content of a variable trough an external command in php?
body: <p>I have a variable that contains a long string. (specifically it contains a few kilobytes of javascript-code)</p>
  
  <p>I want to pass this string trough an external command, in this case a javascript-compressor, and capture the output of the external command (the compressed javascript) in php, assigning it to a variable.</p>
  
  <p>I'm aware that there's classes for compressing javascript in php, but this is merely one example of a general problem.</p>
  
  <p>originally we used:</p>
  
  <pre><code>$newvar = passthru("echo $oldvar | compressor");
  </code></pre>
  
  <p>This works for small strings, but is insecure. (if oldvar contains characters with special meaning to the shell, then anything could happen) </p>
  
  <p>Escaping with escapeshellarg fixes that, but the solution breaks for longer strings, because of OS-limitations on maximum allowable argument-length.</p>
  
  <p>I tried using <code>popen("command" "w")</code> and writing to the command - this works, but the output from the command silently disappears into the void. </p>
  
  <p>Conceptually, I just want to do the equivalent of:</p>
  
  <pre><code>$newvar = external_command($oldvar);
  </code></pre>