#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    UK
    Posts
    9
    Rep Power
    0
    Is there any way to execute remote programs on a server using a Java servlet? I am writing a web based assessment package which must allow for assembly language programs to be compiled and run, probably on the same machine as the server.

    ------------------
    --
    Mark Ogden

    Comments on this post

    • Gran Roguismo agrees
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    35
    Rep Power
    14
    Yes, you can do this like so (this example starts a subshell and executes a command) :

    String[] command = {"/usr/bin/ksh","-c","ls"};
    Process p = Runtime.getRuntime().exec(command);
    BufferedReader results = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String nextLine = results.readLine();
    while (nextLine != null) {
    out.println(nextLine+"<br>");
    nextLine = results.readLine();
    }

    You will have to put this in a try/catch block.

    Success, Ton
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    UK
    Posts
    9
    Rep Power
    0
    That's brilliant! Thanks very much. Works a treat!

    ------------------
    --
    Mark Ogden

IMN logo majestic logo threadwatch logo seochat tools logo