0

How can I either run a batch file from java or better yet, run these commands in java? The closes I got with running the command was

Process process = Runtime.getRuntime().exec("cmd /c start \"C:\\Program Files\\SmartBear\\SoapUI-5.2.1\\bin\\testrunner.bat\"-a-f'W:\\WebServices Migration Project\\crp5\\regression results W:\\WebServices Migration Project\\crp5\\CountryRetrievalCRP10X2Http-soapui-project.xml'");

But that gave some error with those other paths do you know what I would need to modify for this line to work?.

I tried just running the bat file that I made but that also didn’t work. I checked the file path, copied it directly. Saw this bit of code online: Cannot run program "CRP5RegressionTest.bat" (in directory "C:\Users\P621842\Desktop"): CreateProcess error=2, The system cannot find the file specified.

           ProcessBuilder pb = new ProcessBuilder("CRP5RegressionTest.bat");
            pb.directory(new File("C:\\Users\\P621842\\Desktop"));
            Process p = null;
                    try {
                          p = pb.start();
                    } catch (IOException e1) {
                          // TODO Auto-generated catch block
                          e1.printStackTrace();
                    }
            try {
                          int exitStatus = p.waitFor();
                    } catch (InterruptedException e1) {
                          // TODO Auto-generated catch block
                          e1.printStackTrace();
                    }

Here is how the batch file looks like.

@echo off
set SOAPUI_HOME=C:\Program Files\SmartBear\SoapUI-5.2.1\bin\
pushd %SOAPUI_HOME%
call testrunner.bat -a -f"W:\WebServices Migration Project\crp5\regression      results" "W:\WebServices Migration Project\crp5\DFIAccountRetrievalCRP27x1-soapui-project.xml"

Thank,

  • "But that gave some error with those other paths"--> What is the error? post stack trace. – kosa Jul 13 '16 at 16:32
  • Your attempt using runtime didn't work because it was trying to run a program that was named `"cmd /c start \"C:\\Program Files\\SmartBear\\SoapUI-5.2.1\\bin\\testrunner.bat\"-a-f'W:\\WebServices Migration Project\\crp5\\regression results W:\\WebServices Migration Project\\crp5\\CountryRetrievalCRP10X2Http-soapui-project.xml'"`, when you should have run a command named `"cmd"` and passed the arguments in a `String[]` as the second parameter. Similarly for ProcessBuilder - you'll have to parse the lines and separate the command from the parameters – Bohemian Jul 13 '16 at 16:35
  • Ill try that out, thank you. – user2767082 Jul 14 '16 at 13:12

0 Answers0