title: mod_perl and inheriting STDIN in child process
body: <p>I have this old Perl script that is supposed to act as a proxy of sorts between HTTP-based clients and non-HTTP Java server: the client POSTs some data to this Perl script and the script would in turn call the Java server, get the response and return it to the client.</p>
  
  <p>The Perl part calls the server like this:</p>
  
  <pre><code>$servervars = "-DREMOTE_HOST=$ENV{'REMOTE_HOST'}"; 
  #(a few other server variables passed this way)
  
  system "java $servervars -cp /var/www javaserver";
  </code></pre>
  
  <p>and then the Java server would go:</p>
  
  <pre><code>InputStream serverData = System.in;
  serverData.read(); //and read, and read it on
  //....
  //print response:
  System.out.print("Content-type: application/octet-stream\n\n");
  System.out.write(...);
  </code></pre>
  
  <p>Problem is, this works just fine when the Perl script is invoked via CGI, but doesn't work at all if the Perl script is handled by mod_perl (mod_perl2 actually). Apparently the Java part doesn't get the STDIN from Perl (serverData.available() returns 0) and Perl doesn't get the STDOUT back. The latter can be remedied by doing print `java...` (i.e. backticks) instead of system "java...", but I don't know what to do about STDIN.</p>
  
  <p>The Perl script itself is able to read the POSTed data in STDIN. I've also tried to spawn a test Perl script instead of the Java application, and that doesn't get the parent script's STDIN either.</p>
  
  <p>Judging by the description, spawn_proc_prog from Apache2::SubProcess could do the trick (i.e. pass the POST data as STDIN to the child process and get back the child process' output), but it doesn't seem to work if I run anything but another Perl script.</p>
  
  <p>Is there any way to make the child process inherit the parent script's STDIN? I can read the stream in the Perl script and pass its contents as a command-line parameter, but I presume that would be the subject to command-line length limitations, and sometimes there can be a lot of data (like an picture), so I would really like to figure out how to inherit the stream.</p>