Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[URGENT PLEASE]Running a batch file through java  RSS feed

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I run an batch file ,which takes parameters, through Java?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!