-1

Uff... tried to google but with no result.

Hello everybody. I need to run via cmd.exe the next command from java programm (javascript syntax):

"/c cd c:\prb && Processing.bat c:\prb ext.dat auto"

it means i need to change current directory to c:\prb, write "Processing.bat c:\prb ext.dat auto" and press enter.

My Java code is:

String command = "cmd /c start cmd.exe /K cd c:\\prb Processing.bat c:\\prb prb ext.dat auto";
Process pr = Runtime.getRuntime().exec(command);
pr.waitFor();

but it doesn't work. I suppose that i miss some code between "c:\prb" AND "Processing.bat" in the command line.

Could anybody help me?

May12
  • 2,420
  • 12
  • 63
  • 99

2 Answers2

0

I can see at least one mistake: path c:\\prb Processing.bat contains space and therefore must be quoted:

"cmd /c start cmd.exe /K cd \"c:\\prb Processing.bat\" c:\\prb prb ext.dat auto"

I am not sure about c:\\prb prb ext.dat. Is it one path or 2 separate arguments? If it is one argument quote it too.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • yes, it is my mistake. cjrrect: "c:\\prb ext.dat" But now i have mistake: The filename, directory name, or volume label syntax is incorrect. C:\Documents and Settings\DT\workspace\PPM> – May12 Sep 03 '12 at 15:04
0

This time I will write a cope from my memory, I have used like 8 year ago :) What is you trying to solve it is impossible, no that isn't the proper word, but: you want to launch cmd with a specified working directory, than launch a bat file.

Far as I remember:
Launch the .bat, but give a parameter other working directory

Or: launch cmd (1 process) give a param to execute the change directory give another param to execute the bat file. All from Java, it is more complex.

How to do it it is another question.

here is what should be the command like if you do no specify the working directory:

String command = "cmd /c \"c:\prb\Processing.bat\"";

do not forget to change the working directory if you need. 8 years ago I did, sorry if I am robbing your time, just want to help