title: use GNU parallel in a pipe
body: <p>Running the following command does what I want when reading from a file:</p>
  
  <pre><code>parallel --gnu -j2 "echo {} &amp;&amp; sleep 5" &lt; myfile.txt
  </code></pre>
  
  <p>I would like to do something similar with a pipe. Note that I used the following page for inspiration for the pipe reader and writer: <a href="http://www.linuxjournal.com/content/using-named-pipes-fifos-bash" rel="nofollow">http://www.linuxjournal.com/content/using-named-pipes-fifos-bash</a></p>
  
  <p>Here is my pipe reader file:</p>
  
  <pre><code>#!/bin/bash
  
  pipe=/tmp/testpipe
  
  trap "rm -f $pipe" EXIT
  
  if [[ ! -p $pipe ]]; then
      mkfifo $pipe
  fi
  
  while true
  do
      parallel --gnu -j2 "echo {} &amp;&amp; sleep 5" &lt;$pipe
  done
  
  echo "Reader exiting"
  </code></pre>
  
  <p>And here is my writer:</p>
  
  <pre><code>#!/bin/bash
  
  pipe=/tmp/testpipe
  
  if [[ ! -p $pipe ]]; then
      echo "Reader not running"
      exit 1
  fi
  
  
  if [[ "$1" ]]; then
      echo "$1" &gt;$pipe
  else
      echo "Hello from $$" &gt;$pipe
  fi
  </code></pre>
  
  <p>I then run pipeWriter several times, such as</p>
  
  <pre><code>$ ./pipeWriter one
  $ ./pipeWriter two
  $ ./pipeWriter three
  $ ./pipeWriter four
  $ ./pipeWriter five
  $ ./pipeWriter six
  $ ./pipeWriter seven
  $ ./pipeWriter eight
  $ ./pipeWriter nine
  $ ./pipeWriter ten
  $ ./pipeWriter ww
  $ ./pipeWriter wwdfsdf
  $ ./pipeWriter wwdfsdfsddfsd
  $ ./pipeWriter testAgain
  </code></pre>
  
  <p>The shell running pipeReader shows:</p>
  
  <pre><code>$ ./pipeReader 
  one
  four
  eight
  ww
  testAgain
  </code></pre>
  
  <p>First, there is a problem of missing data. Second, parallel does not seem to run in parallel when in the pipe. I would like it to run two jobs at a time (or rather, at most two jobs. If it only has one job that's fine and if another it can start it).</p>
  
  <p>Where am I going wrong?</p>