Launching bat file


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Launching bat file

  1. #1
    Join Date
    Jul 2004
    Posts
    13

    Launching bat file

    Hey Guys,
    Need a little help I am trying to run a bat file in a java program. I have been able to sucessfully launch other ie (paint, word, and others) programs from my java program but I can't seem to get this batch file that runs in the cmd prompt to work. Currently useing
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);
    cmd is a string that contains my the bat file. The only thing I am doing diffrent form the expamles I have seen on the net is trying to launch this program from the action preformed method of a button. Where as all the examples I see on the net use the exec() in the main method. It should work though since I can launch exe files as long as the path is correct. Any help would be great

    Jason

  2. #2
    Join Date
    May 2004
    Posts
    219
    Well, you need to tell us what 'cmd' is, since I am guessing that your problem lies there...

  3. #3
    Join Date
    Jul 2004
    Posts
    13
    cmd is the name of string array.
    that has three slots in the array the first postion cmd[0] is cmd.exe cmd[2] is "\c" and cmd[3] is the bat file "emcxseq".
    I have two question a is this anywhere close to correct be do I need full path if the bat file resides in the same dir as my java files?

    Thanks
    Jason

  4. #4
    Join Date
    May 2004
    Posts
    219
    Well, it should be "/c" not "\c" and I assume you just typed this wrong, but it should be in cmd[1] not cmd[2], 0,1,2... I'm sure that's what you meant. Anyway, if the file is named .bat or .cmd you don't need to use "cmd.exe /c" IIRC.

  5. #5
    Join Date
    Jul 2004
    Posts
    13
    Ok if I am following you correctly I should put the following in cmd[0] "emcxseq.bat" cmd[1] and cmd[2] can hold the aurguments that are need for this bat file to run i.e (destination and file type). If this is correct can I expect to see the command prompt run as part of the output? Reason I ask was the bat file usually when it is run from a cmd prompt echos stuff to the screen to let you know it's progress. also what is IIRC sorry for being such a newbie.

    Jason

  6. #6
    Join Date
    May 2004
    Posts
    219
    That should work. No, you won't see the prompt/output. If you want to see the output, you have to capture it with a stream and print it to the console.

    Edit: IIRC = If I remember correctly

  7. #7
    Join Date
    Jul 2004
    Posts
    13
    Thanks for the help I was waiting to see the command promt and had it right when I tried it the first time it was right I should have check the folder to see if the file was there...Thanks for you help

  8. #8
    Join Date
    Jul 2004
    Posts
    13
    have one other quick question if I wanted to see the output on the screen is it waiting on the input stream of my java program or do I need to do something speacial to get it to so I can right it to the scree?

    Thanks again

  9. #9
    Join Date
    Feb 2004
    Posts
    808
    Originally posted by Drain
    Well, it should be "/c" not "\c" and I assume you just typed this wrong, but it should be in cmd[1] not cmd[2], 0,1,2... I'm sure that's what you meant. Anyway, if the file is named .bat or .cmd you don't need to use "cmd.exe /c" IIRC.
    this depends.. some commands in windows nt class operating systems,. are built into the cmd executable.. so trying to java exec "SET" for example, will not work, as set.exe does not exist.. you must call upon CMD to run it, using the /c switch

    and.. if you notice, the correct way to run a batch file is:

    CMD /c CALL c:\mybatch.bat
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center