Solved

Run bat file in JSP

Posted on 2008-06-12
6
2,141 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 96
fibonacci ten numbers 4 39
varialbe initialization 11 33
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 33
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

778 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