I have a problem in my java code when I want run a file bat whom the name have brackets (Ex: VAL(SAU)-AccType01.bat)
My java code is: File f = new File(pathFileBat); ... run = Runtime.getRuntime(); process = run.exec("cmd /c start " + bat, null, pathClassCommand);
The following message appears: VAL is not recognized as an internal or external command..
If i do: process = run.exec("cmd /c start \"" + f + "\"", null, pathXX);
The windows appears correctly(opening of the good repertory(pathXX)) but the file bat isn't run
Thank you to help me
Joined: Aug 24, 2003
if in doubt - cheat! Im assuming commandLine contains the shell like for the bat file
it means the commandLine variable is written out to the StdIn for the Shell It should work - but i dont have a bat to check!
Joined: Aug 02, 2004
I believe that part of what Tom's suggesting is actually the right way to go about it, rather than cheating. You should open the command window with getRuntime().exec() as you're doing, setting the working directory, and then write your commands to the shell's stdin.
You should really handle stdout and stderr too as failing to do so can easily cause the process to hang. If you search this forum for Runtime.getRuntime() there's a recent thread in which I included a link to a article with source code to do this.