Java ProcessBuilder Pipe [duplicate]

2019-08-05 07:35发布

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

1条回答
Juvenile、少年°
2楼-- · 2019-08-05 08:25

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

查看更多
登录 后发表回答