• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you call a .bat file from a Java program

 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to use the java.lang.Runnable and I coded somthing like thwe following, which does not work. Could anyone tell me what's wrong and how I can execute a file within my java program.
 
prasad bhn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the runtime class object and then invoke the .bat file. i believe it doew work
HTH
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. it works fine. Thanks for your help.
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now, I have this method waitFor(), which waits until my execution is completed. However, it does not work. Is there a .jar that I have to import. I'm using jdk1.2 and I can't seem to find this method. Please. let me know if I have to import something.
 
prasad bhn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have to get a Thread object, on that u have to invoke wait() method to wait until ur process gets completed.
u need to import the below
import java.io.Thread;
[This message has been edited by prasad bhn (edited October 01, 2001).]
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have that option of importing the import you mentioned below:
import java.io.Thread;
Is there a reason why I can't? I think that it's because I'm using j.d.k.1.2.1, tell me what you think.

 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai bob the class Thread is not in "io" package but it is in the default package "lang".It is java.lang.Thread.try using this& u shall finish up u'r job.
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it to function properly. I needed to add a process like shown below:

Process process = Runtime.getRuntime().exec("Script");
process.waitFor();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!