• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2226
  • Last Modified:

Run bat file in JSP

I need to run a bat file in jsp. I used the below method to run but I it seem to only run 2 lines of my bat file, may I know what is the problem??? When I do a double click on the bat, it is working fine !

File file = new File(AppPath2);
Process p = Runtime.getRuntime().exec("cmd.exe /C \"" + batfile + "\"", null, file);

0
KenTan85
Asked:
KenTan85
  • 3
  • 2
1 Solution
 
CEHJCommented:
You need to handle the streams on separate threads. See

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
0
 
KenTan85Author Commented:
what you mean by separate threads??? I do not quite understand from the url.
0
 
CEHJCommented:
You need to read the full article - it's covered in detail
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
As a kludge, you could try the following
Process p = Runtime.getRuntime().exec("cmd.exe /C \"" + batfile + "  2>&1 >nul\"", null, file);

Open in new window

0
 
objectsCommented:
output from external command is buffered, and once that buffer fills the process is blocked.
followwing examples shows you how to avoid the problem by reading any output from the command as it is available.

http://exampledepot.com/egs/java.lang/ReadFromCommand.html
http://www.objects.com.au/java/examples/io/examples/ConsoleExecExample.java

You can the use the output (eg. log it)_ or just ignore it

0
 
objectsCommented:
You may also want to look at user ProcessBuilder instead of exec()

http://java.sun.com/developer/JDCTechTips/2005/tt0727.html

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now