java - Executing cmd file contained in a folder with space -


i trying run cmd file using jdk7u25 following code:

try {             processbuilder pb = new processbuilder(cmd);             pb.directory(workingdir);             proc = pb.start();         } catch (ioexception e) {             system.out.println(e.getmessage());             throw e;         }         // stdout , err stream must read immediatly if not used          // error message?         streaminlet error = new streaminlet(proc.geterrorstream(), "error");          // output?         streaminlet output = new streaminlet(proc.getinputstream(), "output");          // kick them off         error.start();         output.start();          if (wait) {             try {                 exitcode = proc.waitfor();             } catch (interruptedexception e) {                 system.out.println("waiting process interrupted");             }             if (addmetainfo)                 system.out.println("return value = " + exitcode);         } 

where cmd=[cmd.exe, /c, c:\my root\scripts\windows\tools\mycli.cmd, -c, c:\local disk d\my tutorial\regressiontests.xml, -d, 02_recordviewer_test, -l"error"]

but doesn't work , following output.

'c:\my' not recognized internal or external command,

operable program or batch file.

i have made necessary changes jdk7u21 issue adding explicit "cmd.exe /c" before calling cmd file. using processbuilder class mentioned in jdk7u21 issue.

it works fine if cmd file trying execute placed in c:\myroot i.e. folder without space in it's name.

can please help?

you need enclose paths in quotation marks cmd requires:

string[] cmd = {"cmd.exe", "/c", "\"c:\\my root\\scripts\\windows\\tools\\mycli.cmd\"", "-c", "\"c:\\local disk d\\my tutorial\\regressiontests.xml\"",.....}; 

update discussed via chat, problem seems processbuilder passing parameters cmd.exe. have complete path executable, cmd.exe no needed @ all. command this:

string[] cmd = {"\"c:\\my root\\scripts\\windows\\tools\\mycli.cmd\"", "-c", "\"c:\\local disk d\\my tutorial\\regressiontests.xml\"",.....}; 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -