This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes calling a shell script or a batch file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "calling a shell script or a batch file" Watch "calling a shell script or a batch file" New topic
Author

calling a shell script or a batch file

Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling a shell script or a batch file
 
Similar Threads
IBM Websphere 4.0 console commands
Reg: ActionListener
arguments of System.exit()
Batch File
exe of a jar file + passing parameter from cmd prompt to exe