Solved

Run bat file in JSP

Posted on 2008-06-12
6
2,162 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
Independent Software Vendors: 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!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 53
How to configure empty element in XML Document parser? 15 57
Where to place postgres JDBC driver jar on tomcat 8 65
Bitwise and to sum elements 2 48
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…

739 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