Solved

Run an exe file from JSP

Posted on 2001-09-18
6
950 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
Highfive Gives IT Their Time Back

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 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

706 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

20 Experts available now in Live!

Get 1:1 Help Now