title: From Perl, spawn a shell, configure it, and fork the STDOUT
body: <p>I use a Perl script to configure and spawn a compiled program, that needs a subshell configured a certain way, so I use <code>$returncode = system("ulimit -s unlimited; sg ourgroup 'MyExecutable.exe'");</code></p>
  
  <p>I want to capture and parse the STDOUT from that, but I need it forked, so that the output can be checked while the job is still running. This question comes close:
  <a href="https://stackoverflow.com/questions/634508/how-can-i-send-perl-output-to-a-both-stdout-and-a-variable">How can I send Perl output to a both STDOUT and a variable?</a> The highest-rated answer describes a function called <code>backtick()</code> that creates a child process, captures <code>STDOUT</code>, and runs a command in it with <code>exec()</code>.</p>
  
  <p>But the calls I have require multiple lines to configure the shell. One solution would be to create a disposable shell script:</p>
  
  <pre>#disposable.sh
      #!/bin/sh
      ulimit -s unlimited
      sg ourgroup 'MyExecutable.exe'</pre>
  
  <p>I could then get what I need either with <code>backtick(disposable.sh)</code> or <code>open(PROCESS,'disposable.sh|')</code>.</p>
  
  <p>But I'd really rather not make a scratch file for this. <code>system()</code> happily accepts multi-line command strings. How can I get <code>exec()</code> or <code>open()</code> to do the same?</p>