• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem of brackets running file bat

 
ed lapoign´┐Że
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic