• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling a shell script or a batch file

 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have a web application written in struts in deployed on tomcat. i want to provide use with a button on my UI, so when the button is pressed it calls shell or a bat file which will start an independent java program which will do some file export stuff. May i know how can i can i execute the shell or the batch srcipt.
Any idea
Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34668
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rashid,
To call an operating system shell script or batch file, you use the Runtime.exec() API. In your case, you can just call the Java program:

There's no reason to introduce additional complexity since you are calling other Java code.

With either approach, you may want to start the other program in a new Thread if you want it to be asynchronous.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne,

The other thing i wanted to know is that i dont want user to start duplicate process. So for Example if the user already clicked the file and the file generation is in process, i dont want to start one more process when i the user accidently clicks on the button. May i know how can i check for the process whether it is already running

Thanks
Rashid
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic