5

Possible Duplicate:
ProcessBuilder redirecting output

The following code:

ProcessBuilder pb = new ProcessBuilder(new String[] {"echo", "some text", ">", "test"});

keeps returning "some text > test".

What am I doing wrong?

EDIT:

this worked

ProcessBuilder pb = new ProcessBuilder(new String[] {"bash", "-c", "echo sometext > test"});
Community
  • 1
  • 1
pedja
  • 3,285
  • 5
  • 36
  • 48
  • Accepted answer from [link](http://stackoverflow.com/questions/5740390/printing-my-macs-serial-number-in-java-using-unix-commands/5740673#5740673) worked – pedja Jan 28 '13 at 12:11
  • 1
    Cool. Glad you got it sorted, and thanks for reporting back. – Andrew Thompson Jan 28 '13 at 12:15

1 Answers1

5

Try following

    ProcessBuilder pb = 
new ProcessBuilder("cmd.exe", "/c" ,"echo", "some text", ">", "test");

This is for windows

Actually 'Echo' is not a command its an internal command of the shell (cmd.exe) in windows and "bash" in linux or unix. So , for Unix/Linux

    ProcessBuilder pb = 
new ProcessBuilder("bash", "-c","echo \"some text\" >test"); 
Tyutyutyu
  • 171
  • 2
  • 6
TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57