Results 1 to 6 of 6
  1. #1
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

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

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,280
    Rep Power
    6

    Default 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

  3. #3
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

    Default Re: Browse a file and run an .exe file

    Quote Originally Posted by gimbal2 View Post
    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
    Yup, am doing this in servlet. Am using jsp to create the view with buttons.

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,280
    Rep Power
    6

    Default 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

  5. #5
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

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

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: Browse a file and run an .exe file

    But that code just runs the exe.
    There's no mention there of the file the client has uploaded.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 12-15-2012, 02:37 AM
  2. Replies: 15
    Last Post: 02-16-2012, 04:43 PM
  3. Replies: 6
    Last Post: 12-01-2010, 06:31 AM
  4. Replies: 1
    Last Post: 08-04-2010, 04:24 PM
  5. Replies: 0
    Last Post: 02-11-2009, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •