title: running Echo from Java
body: <p>I'm trying out the Runtime.exec() method to run a command line process.</p>
  
  <p>I wrote this sample code, which runs without problems but doesn't produce a file at c:\tmp.txt.</p>
  
  <pre><code>String cmdLine = "echo foo &gt; c:\\tmp.txt";
  Runtime rt = Runtime.getRuntime();
  Process pr = rt.exec(cmdLine);
  
  BufferedReader input = new BufferedReader(
                             new InputStreamReader(pr.getInputStream()));
  String line;
  
  StringBuilder output = new StringBuilder();
  while ((line = input.readLine()) != null) {
      output.append(line);
  }
  
  int exitVal = pr.waitFor();
  
  logger.info(String.format("Ran command '%s', got exit code %d, output:\n%s", cmdLine, exitVal, output));
  </code></pre>
  
  <p>The output is </p>
  
  <blockquote>
    <p>INFO  21-04 20:02:03,024 - Ran command
    'echo foo > c:\tmp.txt', got exit code
    0, output: foo > c:\tmp.txt</p>
  </blockquote>