• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

execute bat file from jsp

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.......
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..........
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic