Solved

Run bat file in JSP

Posted on 2008-06-12
6
2,121 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now