title: Scala - shell commands with pipe
body: <p>I'm a Scala beginner and I'm writing a wrapper for invoking shell commands. Currently I'm trying to invoke shell commands with pipes from a specified directory.</p>
  
  <p>To achieve this I wrote simple utility:</p>
  
  <pre><code>def runCommand(command: String, directory: File): (Int, String, String) = {
  
    val errbuffer = new StringBuffer();
    val outbuffer = new StringBuffer();
  
    //run the command
    val ret = sys.process.Process(command, directory) !
    //log output and err
    ProcessLogger(outbuffer append _ + "\n", outbuffer append _ + "\n");
  
    return (ret, outbuffer.toString(), errbuffer.toString());
  }
  </code></pre>
  
  <p>However with this utility I can't use pipes, for example:</p>
  
  <pre><code>runCommand("ps -eF | grep -i foo", new File("."));
  </code></pre>
  
  <p>First I thought, that pipes are shell's functionality, so I tried "/bin/sh -c ps -eF | grep -i foo", but it seems that expression from the right of the pipe was ignored.</p>
  
  <p>I also tried running commands with ! syntax (sys.process._ package), but I couldn't figure out, how to call command from specified directory (without using "cd").</p>
  
  <p>Could you please advice me, how to do this correctly?</p>