Solved

Run an exe file from JSP

Posted on 2001-09-18
6
952 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDFBox - convert image to PDF, PDF resolution 3 110
eclipse package explorer vs project explorer view 2 73
Java - Why doesn't this JFrame work 3 40
eclipse shortcuts 9 45
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

943 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

4 Experts available now in Live!

Get 1:1 Help Now