• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execute bat file from jsp

 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1755
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic