title: Why open function doesn't interpret the option of my command every time?
body: <p>I want to use <code>open</code> function to run the following commands:</p>
  
  <pre class="lang-sh prettyprint-override"><code>&gt; echo "toto\ntata"
  toto
  tata
  &gt; echo -e "toto\ntata"
  toto
  tata
  &gt; echo -E "toto\ntata"
  toto\ntata
  &gt; echo -n "toto\ntata"
  toto\ntata
  </code></pre>
  
  <p>Note that for the last command, there is no trailing new line.</p>
  
  <p>So I have the following script:</p>
  
  <pre class="lang-perl prettyprint-override"><code>use strict;
  
  sub run_cmd {
      my ($cmd) = @_;
      my $fcmd;
  
      print("Run $cmd\n");
  
      open($fcmd, "$cmd |");
      while ( my $line = &lt;$fcmd&gt; ) {
          print "-&gt; $line";
      }
      close $fcmd;
  }
  
  eval{run_cmd('echo "toto\ntata"')};
  eval{run_cmd('echo -e "toto\ntata"')};
  eval{run_cmd('echo -E "toto\ntata"')};
  eval{run_cmd('echo -n "toto\ntata"')};
  </code></pre>
  
  <p>But when I run it, I get this results:</p>
  
  <pre><code>Run echo "toto\ntata"
  -&gt; toto
  -&gt; tata
  Run echo -e "toto\ntata"
  -&gt; -e toto
  -&gt; tata
  Run echo -n "toto\ntata"
  -&gt; toto
  -&gt; tataRun echo -E "toto\ntata"
  -&gt; -E toto
  -&gt; tata
  
  </code></pre>
  
  <p>We can see the <code>-n</code> option is correctly interpreted by <code>open</code>, because there is no newline at the end of the text, but it is not the case for the options <code>-e</code> and <code>-E</code>. Worse, there are printed by <code>echo</code>.</p>
  
  <p>Why my options are not interpreted by <code>open</code> every time? What should I do to get a correct output?</p>