tzoorp
tzoorp

Reputation: 183

sending command to terminal from java with space in it

I am working on a java program, where i need to invoke a bash script that takes a string as an argument. so I've written the code:

Process p = Runtime.getRuntime().exec("./script \"message send\"");

but it seems as if the terminal isn't recognizing the quotes (") as quotes, and referring to the term "message send" as two arguments: "message and send", and so the script is not invoked properly.

anyone have any idea what i can do?

Upvotes: 2

Views: 482

Answers (1)

BDRSuite
BDRSuite

Reputation: 1612

You can perform this by using ProcessBuilder.

ProcessBuilder processBuilder = new ProcessBuilder();
p.command("cmd_to_run", "args_if_any");
p.start();

Upvotes: 2

Related Questions