title: bash redirect stdout and stderr to separate commands over ssh
body: <p>I am using BASH 4.  I am trying to find a way to legitimately prepend output to indicate the type of output that it is.  I am able to do this with something kind of like this...</p>
  
  <pre><code>ls -l /tmp/abcdefgh 2&gt; &gt;(sed 's/^/stderr: /') 1&gt; &gt;(sed 's/^/stdout: /')
  stderr: ls: cannot access /tmp/abcdefgh: No such file or directory
  
  ls -l /tmp/ 2&gt; &gt;(sed 's/^/stderr: /') 1&gt; &gt;(sed 's/^/stdout: /')
  stdout: drwxr-xr-x 3 root root 4096 2010-10-15 09:08 fsck
  stdout: drwxr-xr-x 2 root root 4096 2010-09-10 06:01 kernel
  stdout: drwxr-xr-x 2 root root 4096 2010-09-10 06:01 temp_keys
  ...
  </code></pre>
  
  <p>This seems to do the trick when I am logged in via SSH and run it interactively.  However, this does not always work right if I try to just run the command as a remote command via ssh with the command in quotes.  I can always get the stdout lines, but sometimes not the stderr lines.</p>
  
  <p>This will produce output...</p>
  
  <pre><code>ssh root@server1 "ls -l /tmp/ 2&gt; &gt;(sed 's/^/stderr: /') 1&gt; &gt;(sed 's/^/stdout: /')"
  </code></pre>
  
  <p>This will not produce even an error message...</p>
  
  <pre><code>ssh root@server1 "ls -l /tmp/abcdefgh 2&gt; &gt;(sed 's/^/stderr: /') 1&gt; &gt;(sed 's/^/stdout: /')"
  </code></pre>
  
  <p>However, this shows the wget status results as stderr results (which it should)</p>
  
  <pre><code>ssh root@server1 "wget http://server2/package.rpm 2&gt; &gt;(sed 's/^/stderr: /') 1&gt; &gt;(sed 's/^/stdout: /')"
  </code></pre>