-
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
-
Well, you need to tell us what 'cmd' is, since I am guessing that your problem lies there...
-
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
-
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.
-
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
-
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
-
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
-
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
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks