Results 1 to 6 of 6
- 09-09-2013, 11:32 PM #1
Member
- Join Date
- Sep 2013
- Posts
- 11
- Rep Power
- 0
Browse a file and run an .exe file
Hi,Could some one help me in resolving this.I would appreciate for any help.
In a jsp page I have a browse file option and submit button. When I browse the file and click submit, a .exe file should run based on the browsed file.(Please note that the browsed file is not the .exe file).This I want to do from a web page.
The same can be done from the command prompt in the following way:
cmd: C:\tools\server\grd.exe -c C:\files\test.lic
where -c C:\files\test.lic is the command to list the files in that location.
C:\tools\server\grd.exe is the command to run the .exe file.
My requirement is I have to do this in a webpage. As it works in the command prompt the same way it should work in the webpage but I have to browse the file and then run the .exe file.
- 09-10-2013, 08:47 AM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Browse a file and run an .exe file
Don't do it in a JSP, do it in a servlet. And since a servlet is basically just a Java class, you are free to use the Runtime or Process class in it to invoke a system command.
When Runtime.exec() won't - JavaWorld"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 09-10-2013, 03:28 PM #3
Member
- Join Date
- Sep 2013
- Posts
- 11
- Rep Power
- 0
- 09-10-2013, 03:38 PM #4
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Browse a file and run an .exe file
Excellent. But did you also manage to implement your requirement now?
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 09-12-2013, 03:58 PM #5
Member
- Join Date
- Sep 2013
- Posts
- 11
- Rep Power
- 0
Re: Browse a file and run an .exe file
Not yet. I mean though i browse different files and click submit button it is showing me the result of the same file that I selected first. below is the code snippet.
java code:
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
try{
res.setContentType("text/html;charset=UTF-8");
PrintWriter out = res.getWriter();
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("C:\\tools\\server\\grd.exe " );
out.println("ServerStarted");
}catch (Throwable t)
{
t.printStackTrace();
}
finally {
} }
}
jsp code:
<form action="clpstart" METHOD="GET" enctype="multipart/form-data">
<input type="file" name=browsefile size="150" />
<input type="submit" name="start" value="StartServer" />
</form>
</td>
I did not even hardcoded the file that I want to browse but still it takes the same file that I mentioned in my question above.
- 09-12-2013, 05:55 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Similar Threads
-
HashMap with Objects, reading from file, writing to file. (note system)
By Java Dude in forum New To JavaReplies: 0Last Post: 12-15-2012, 01:37 AM -
Open a jar file with button swing and load this file.jar in a desktop pane
By lordhark in forum AWT / SwingReplies: 15Last Post: 02-16-2012, 03:43 PM -
Write a program that sorts data from a text file and sort them in a file
By danmgz45 in forum New To JavaReplies: 6Last Post: 12-01-2010, 05:31 AM -
pack200 .gz file unpack and create .jar file in browser(speed test).
By maheshsardar in forum Java AppletsReplies: 1Last Post: 08-04-2010, 03:24 PM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM
Bookmarks