Forum Discussion

hellrid1's avatar
hellrid1
Occasional Contributor
12 years ago

run SoapUI from a .bat file in a Java program

I am trying to run SoapUI from a .bat file in a java program.

Running the Java program creates XML files in a directory, and then I run the .bat file to create a sub-directory with the responses.
I would like to combine these two steps.

I've tried several variations, but the Main java code looks like this:

public static void main(String[] args) {
try {
System.out.println("begin test");

Process p = Runtime.getRuntime().exec("cmd /c start \"C:/Documents and Settings/Hellrid1/Desktop/runSoapUi.bat\"");
p.waitFor();

System.out.println("end test");

} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}


I've also tried to run it like this:

String[] commands = new String[]{"cd C:\\Program Files\\SmartBear\\soapUI-Pro-4.0.1\\bin"}; // This will test the first command

/* and add the following to the command array
"cmd.exe /C testrunner.bat" +
" -s\"RealTimeRatingServiceSoapBinding TestSuite\" " +
"-c\"RTR-Rate Revision Request TestSuite\" " +
"\"C:/Documents and Settings/Hellrid1/Desktop/SoapUICmd/RTR-Test-soapui-project.xml",
"pause"};
*/
Process p = Runtime.getRuntime().exec(commands);


but was unsuccessful.

The batch file named runSoapUi.bat contains this code to run a SoapUI project named RTR-Test-soapui-project.xml

cd C:\Program Files\SmartBear\soapUI-Pro-4.0.1\bin\
cmd.exe /C testrunner.bat -s"RealTimeRatingServiceSoapBinding TestSuite" -c"RTR-Rate Revision Request TestSuite" "C:\Documents and Settings\Hellrid1\Desktop\SoapUICmd\RTR-Test-soapui-project.xml"
pause

5 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    hmm.. have you tried

    Runtime.getRuntime().exec( "cmd.exe /C testrunner.bat -s\"RealTimeRatingServiceSoapBinding TestSuite\" -c\"RTR-Rate Revision Request TestSuite\" \"C:\Documents and Settings\Hellrid1\Desktop\SoapUICmd\RTR-Test-soapui-project.xml\"", null, "C:\\Program Files\\SmartBear\\soapUI-Pro-4.0.1\\bin" )

    ?

    If this doesn't work - what error code / message do you get ?

    regards,

    /Ole
    SmartBear Software
  • hellrid1's avatar
    hellrid1
    Occasional Contributor
    I needed to add a \\ to the \'s in C:\Documents and Settings\Hellrid1\Desktop\SoapUICmd\RTR-Test-soapui-project.xml\

    The modified command is :

    Runtime.getRuntime().exec( "cmd.exe /C testrunner.bat -s\"RealTimeRatingServiceSoapBinding TestSuite\" -c\"RTR-Rate Revision Request TestSuite\" \"C:\\Documents and Settings\\Hellrid1\\Desktop\\SoapUICmd\\RTR-Test-soapui-project.xml\"", null, "C:\\Program Files\\SmartBear\\soapUI-Pro-4.0.1\\bin" );

    After that, I am getting a compiler error message from the Eclipse IDE which says:

    "The method exec(String, String[], File) in the type Runtime is not applicable for the arguments (String, null, String)"
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    ok.. then try


    Runtime.getRuntime().exec( "cmd.exe /C testrunner.bat -s\"RealTimeRatingServiceSoapBinding TestSuite\" -c\"RTR-Rate Revision Request TestSuite\" \"C:\\Documents and Settings\\Hellrid1\\Desktop\\SoapUICmd\\RTR-Test-soapui-project.xml\"", (String[])null, "C:\\Program Files\\SmartBear\\soapUI-Pro-4.0.1\\bin" );

    any better?

    /Ole
  • hellrid1's avatar
    hellrid1
    Occasional Contributor
    This works :

    Process p = null;
    File execFile = new File ("C:\\Program Files\\SmartBear\\soapUI-Pro-4.0.1\\bin");
    try {
    p = Runtime.getRuntime().exec( "cmd.exe /C testrunner.bat -s\"RealTimeRatingServiceSoapBinding TestSuite\" -c\"RTR-Rate Revision Request TestSuite\" \"C:\\Documents and Settings\\Hellrid1\\Desktop\\SoapUICmd\\RTR-Test-soapui-project.xml\"", (String[])null, execFile );
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    Now I need to make the Main calling routine to wait until the SoapUI process finishes so that I can parse the XML after it is done. I tried:

    try {
    p.waitFor();
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    but when I do this, the SoapUI process does not start.

    Thank You Very much!
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    sorry - but general support on how to use the java Runtime and Process classes is outside of our support offering.

    thanks for your understanding!

    regards,

    /Ole
    SmartBear Software