Can't remove/install tomcat service with ProcessBuilder

Viewed 91

This command works via batch-file:

c:\tomcat\bin\tomcat7.exe //DS//"A TestService"

The same statement doesn't work with ProcessBuilder:

 public static void removeService() throws Exception
 {
     String tomcatBinPath = "c:\\tomcat\\bin";
     File binFolder = new File(tomcatBinPath);
     String[] parms= new String[4];
     parms[0] = "cmd";
     parms[1] = "/c";
     parms[2] = tomcatBinPath + "\\tomcat7.exe";
     parms[3] = "//DS//\"A TestService\"";
     ProcessBuilder pb = new ProcessBuilder(parms);
     ProcessBuilder newPb = pb.directory(binFolder);
     newPb = newPb.redirectErrorStream(true);
     Process proc = newPb.start();
     int result = proc.waitFor();
     System.out.println(result);
 }

The result is always 9 and the service is not removed.

NOTE:
The problem seems to be the SPACE/BLANK inside the service-name.
I have no problems with ProcessBuilder if the service-name contains no SPACES/BLANKS!

Question:
How to use ProcessBuilder in such a case (SPACES/BLANKS in service-name)?

0 Answers
Related