Reputation: 147
Good day to all experts,
Hope to have some advice on this trivial issue of mine.
I am trying to execute the following syntax while passing the arguments testcase1
,testdata1
and testresult
to jar_filepath
,tc
,test_data
and test_result
respectively
Runtime.getRuntime().exec("cmd /c start cmd /k java -jar "+jar_filepath + tc + test_data + test_result);
However, upon execution, there was an error as follow:
Error: Unable to access jarfile C:\TestAutomation\Jar\Test1.jartestcase1testdata1testresult2
where all the arguments' space is not applied.
Hope to have advice on the proper way to write the code for execution at the exec() level.
Thank you in advance.
Upvotes: 1
Views: 597
Reputation: 33905
Your way does not add spaces before the arguments. That would look like this:
Runtime.getRuntime().exec("cmd /c start cmd /k java -jar "
+ jar_filepath + " " + tc + " " + test_data + " " + test_result);
But if you use a String[]
this is done automatically:
String[] command = {
"cmd /c start",
"cmd /k java -jar " + jar_filepath,
tc,
test_data,
test_result
};
Runtime.getRuntime().exec(comand);
Upvotes: 1