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 JSP and the fly likes execute bat file from jsp 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 » Java » JSP
Bookmark "execute bat file from jsp" Watch "execute bat file from jsp" New topic
Author

execute bat file from jsp

narayana Ega
Greenhorn

Joined: Aug 23, 2012
Posts: 26
problem with executing bat file from jsp....

i wrote like this....

Process proc = Runtime.getRuntime().exec("cmd.exe /c start C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/bscm/Schedule.bat");
proc.waitFor();

but it is not working............

can any one help me to get solution.......
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

hi Narayana,

I made another batch file where i print simple echo and it worked fine in jsp , there should be some other problem.
Try to check it by making simple batch file containing echo.

I used the same code you posted.


Second thing jsp is wrong place to execute batch file you should put it in the servlet.

Regards
Jatan
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Go read the javadocs for the java.lang.Process class.

Pay particular attention to the need to handle the standard and error output streams.

You should try to learn about handling a .bat execution by writing a separate class, NOT playing with JSP


Bill
narayana Ega
Greenhorn

Joined: Aug 23, 2012
Posts: 26
I used this eventhough it is not working

String batFile ="C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps\\scmf\\Schedule.bat";
Process p = Runtime.getRuntime().exec("cmd /c start "+batFile);

can any one help me ........

thanks..........
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

narayana Ega wrote:I used this eventhough it is not working

String batFile ="C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps\\scmf\\Schedule.bat";
Process p = Runtime.getRuntime().exec("cmd /c start "+batFile);

can any one help me ........

thanks..........


You most definitely need to read all the sections of http://www.javaworld.com/jw-12-2000/jw-1229-traps.html and implemens ALL the recommendations.

You should isolate the code into a separate class that is testable outside of the your JSP. Please please please take notice of the traps article and make sure that you pay proper attention to the quoting of file names,
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Can you give more information than "it is not working..."?

What happens when you run it?
Do you get an error message?
Does it complete, but not do what you expect?
Does it put too much sugar in your coffee?

My second question would be - why do you need to trigger an external operation in this manner?
Doing so normally smacks of bad design. What does calling this windows specific batch file accomplish that you can't do in java?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: execute bat file from jsp
 
Similar Threads
Not able to call a bat file from JAVA
keep cmd window open after System.exit(0) (.bat file)
To create a desktop short cut icon for the standalone application
run bat file within java
I feel kinda dumb but...