Solved

Run an exe file from JSP

Posted on 2001-09-18
6
958 Views
Last Modified: 2011-10-03
I would like to execute an exe file from a JSP page. How should i do that? The JSP page and the exe file are located in the same server.

for example:
I have a jsp page(RunExe.jsp) which need to execute an exe file that located at C:\ExeFile\ExeFile.exe

When user request the RunExe.jsp, the jsp page will pass some parameter to ExeFile.exe and execute it. After that the ExeFile.exe will return the result back to the RunExe.jsp and the result will displayed out.


How should i do that? What package should i import? Need advise and example code. Appreciate any help.
0
Comment
Question by:aGuyNameRay
6 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 6490341
Runtime.getRuntime().exec(...);
0
 
LVL 1

Author Comment

by:aGuyNameRay
ID: 6490481
The exe file pass out a result, how can i get the result and display it out?
0
 
LVL 1

Author Comment

by:aGuyNameRay
ID: 6490491
The exe file pass out a result, how can i get the result and display it out?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 6490516
Process p = Runtime.getRuntime().exec("yourApp.exe");
InputStream is = p.getInputStream();
int n;
while ((n = is.read()) != -1)
{
  // save read char
}
0
 
LVL 2

Expert Comment

by:ia_ia_ia_1
ID: 6490520
Something like:

            Process pr = Runtime.getRuntime().exec("cmd.exe");  // replace with you exe


            pr.waitFor();

            java.io.InputStream in = pr.getInputStream();

            java.io.InputStreamReader rdr = new java.io.InputStreamReader(in);
            char[] buffer = new char[1024];

            while (true) {
                int i = rdr.read(buffer);
                if (i == -1) break;
                System.out.print(buffer);
            }

            rdr.close();
0
 

Expert Comment

by:hieutd
ID: 6490879
Listening...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 42
web services creation SOAP vs REST 5 57
Java Restore security prompts not working 10 63
ejb entity bean example issue 2 17
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…
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

829 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