Solved

Run an exe file from JSP

Posted on 2001-09-18
6
961 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
[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
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to configure empty element in XML Document parser? 15 57
DTD and JAVA versions 1 54
using executorService 3 16
Java regex 5 19
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

737 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