[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Run bat file in JSP

Posted on 2008-06-12
6
Medium Priority
?
2,201 Views
Last Modified: 2008-06-14
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
Comment
Question by:KenTan85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21768108
You need to handle the streams on separate threads. See

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
0
 

Author Comment

by:KenTan85
ID: 21768132
what you mean by separate threads??? I do not quite understand from the url.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21768163
You need to read the full article - it's covered in detail
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 21768184
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
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 21768518
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
 
LVL 92

Expert Comment

by:objects
ID: 21768569
You may also want to look at user ProcessBuilder instead of exec()

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

0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question