Run a command from java that may contain spaces

I am trying to execute the following command from a java program: java -jar /opt/plasma/fr.inria.plasmalab.plasmalab-1.3.4.jar -t -a montecarlo -A"Total samples"=1000 -m models/translated/plasma/NaCl2.rml:rml --format csv -r models/translated/plasma/NaCl2.bltl:bltl

with the following code:

String totalSample  = "-A\"Total samples\"=1000";
String mcCommand = "java -jar " + MChecker.getAppPath() + " -t "
                + "-a " + "montecarlo " + totalSample
                + " -m " + mcModelRelPath + ":rml " + "--format " + "csv "
                + "-r " + customQueryRelPath + ":bltl";

Process process = Runtime.getRuntime().exec(mcCommand);
        int errCode = process.waitFor();
        //then get the output, and error

But this leads to the following error: Incorrect parameter description: The dynamic parameter expected the value of the form a = b, but received: "Total

I ran the same command in the terminal and it worked without any problems. But when I create a command in Java and try to call the tool, it does not work.

I think this is confusing due to a parameter totalSamplethat includes a space. What I did next was put a "\" space in paramater ( String totalSample = "-A\"Total\\ samples\"=1000";), but he still refused to accept it. This gave the following error: Incorrect description of the parameter: The dynamic parameter expected the value of the form a = b, but received: "Total \

ProcessBuilder, :

 String[] mcCommand = {"java", "-jar", MChecker.getAppPath(), "-t",
         "-a", "montecarlo",totalSample, "-m",
         mcModelRelPath + ":rml", "--format", "csv", "-r",
         customQueryRelPath + ":bltl" };

ProcessBuilder pb = new ProcessBuilder(mcCommand);
Process process = pb.start();
process.waitFor();

.

- - , Java, ?

BTW: Windows, , Ubuntu.

+4
2

, Java Process ProcessBuilder . , . , .

String mcCommand[] = {
            "/bin/sh",
            "-c",
            "java -jar /opt/plasma/fr.inria.plasmalab.plasmalab-1.3.4.jar -t -a montecarlo "+totalSample+" -m models/translated/plasma/NaCl2.rml:rml --format csv -r models/translated/plasma/NaCl2.bltl:bltl" };

, , .

0

Total samples ProcessBuilder:

ProcessBuilder pb = new ProcessBuilder("java", "-jar", MChecker.getAppPath(), "-t",
        "-a", "montecarlo", "-ATotal samples=1000",
        "-m", mcModelRelPath + ":rml", "--format", "csv",
        "-r", customQueryRelPath + ":bltl");
//...
0

Source: https://habr.com/ru/post/1598925/


All Articles