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.
The moose likes Java in General and the fly likes problem of brackets running file bat Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "problem of brackets running file bat" Watch "problem of brackets running file bat" New topic
Author

problem of brackets running file bat

ed lapoign�e
Greenhorn

Joined: Aug 20, 2004
Posts: 1
Hello.

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
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
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.

Jules
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Intermediate forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: problem of brackets running file bat
 
Similar Threads
Running a .bat/ .cmd file from Java
Writing to a terminal from a Java program
Execute cmd + bat + command
problem with Runtime.getRuntime().exec when running java in .bat
start weblogic server in Java code