title: How can I get STDERR and STDOUT of a command executed on a remote machine through SSH in Perl?
body: <p>I have to connect to a remote machine via SSH executed through Expect module. I have to access the <code>STDERR</code>/<code>STDOUT</code> separately if possible and look at the output. I can redirect the output of the script e.g.</p>
  
  <pre><code>$command = "ssh &lt;script&gt; 2&gt;/tmp/stderr.output"
  $exp = Expect-&gt;spawn($command) or die "Cannot spawn\n";;
  my @command1= $exp-&gt;expect(5);
  </code></pre>
  
  <p>but then I have to remotely connect again to check <code>stderr.output</code>. 
  Is there a way that expect returns the <code>STDERR</code>/<code>STDOUT</code> separately.</p>