1

I have a shell command my_command that accepts a pipe as input , eg

echo "test" | my_command param1 param2

I tried this:

cmd.add("echo");
cmd.add( "test");
cmd.add("| my_command");
cmd.add(param1);
cmd.add(param2);

but i did I not get desired result. cmd is a list declared using ArrayList. thanks

dorothy
  • 1,213
  • 5
  • 20
  • 35

1 Answers1

2

ProcessBuilder can run only programs but echo is not a program but one of cmd's (in Windows) command. You should run cmd /c echo ... in Java

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275