Reputation: 53
I need to build the following command in linux using ProcessBuilder:
sudo packit -t UDP -S 1000 -D 1200 -s 127.0.0.1 -d 192.168.1.1 -c 5 -n 12345 -p '0x 80 64 45 78 00 00 27'
I tried with the following code:
commands.add("sudo"); commands.add("packit");
commands.add("-t"); commands.add("UDP");
commands.add("-S"); commands.add("1000");
commands.add("-D"); commands.add("1200");
commands.add("-s"); commands.add("127.0.0.1");
commands.add("-d"); commands.add("192.168.1.1");
commands.add("-c");
String a = "5"; commands.add(a);
String b = "-n 12345"; commands.add(b);
String c = "-p '0x 80 64 45 78 00 00 27'"; commands.add(c);
ProcessBuilder pb = new ProcessBuilder(commands);
Process process = pb.start();
There isn't syntax error but the result is not same with terminal's result.
When I delete String c = "-p '0x 80 64 45 78 00 00 27'"; commands.add(c);
.I get same result with terminal's result. I think the problem is apostrophe ('), please help me to resolve this problem.
Upvotes: 1
Views: 234
Reputation: 182000
I think these are wrong:
String b = "-n 12345"; commands.add(b);
String c = "-p '0x 80 64 45 78 00 00 27'"; commands.add(c);
The option (-n
, -p
) is separate from its argument:
commands.add("-n"); commands.add("12345");
commands.add("-p"); commands.add("0x 80 64 45 78 00 00 27");
Note also the lack of additional quotes there. Those are only needed for the shell.
Upvotes: 1