This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
Tom Hill
Ranch Hand
Joined: Aug 24, 2003
Posts: 115
posted
0
if in doubt - cheat! Im assuming commandLine contains the shell like for the bat file
do:
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!
Tom
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
posted
0
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.