This question already has an answer here:
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
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