File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes [URGENT PLEASE]Running a batch file through java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "[URGENT PLEASE]Running a batch file through java" Watch "[URGENT PLEASE]Running a batch file through java" New topic
Author

[URGENT PLEASE]Running a batch file through java

Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
How do I run an batch file ,which takes parameters, through Java?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Try:


See the documentation for the Runtime class for more information.
However, I seem to recall running into a problem where this would not work for batch files for some reason (this was versions of Java ago; I don't remember the reason). I used the JNI and created a native method that simply wrapped C's sytem(char*) function. That worked nicely.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

However, I seem to recall running into a problem where this would not work for batch files for some reason (this was versions of Java ago; I don't remember the reason).

It'll work. You must consume everything from the created process' stdout and stderr streams or the process will lock up.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [URGENT PLEASE]Running a batch file through java