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

    Default Exposing command line directory list as REST API shows blank page

    Am trying to expose the following command line directory list as a RestApi with plain text .It does print the list of c directory in console with system.out.println but does not show the output on the uri page,its empty.Example:

    http://localhost:Project/show/dir is blank. Any suggestions as to where am going wrong. Below is the code snippet.

    public class ShowDirectory {

    String s=null;

    public String showDir() {
    try{

    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec("cmd /c dir");

    BufferedReader input = new BufferedReader(new InputStreamReader
    (pr.getInputStream()));

    String line=null;

    while((line=input.readLine()) != null) {
    System.out.println(line);
    }

    int exitVal = pr.waitFor();
    System.out.println("Exited with error code "+exitVal);

    } catch(Exception e) {
    System.out.println(e.toString());
    e.printStackTrace();
    }
    return s;
    }
    }Service Class:

    @Path("show")

    public class StartDirectory {

    @GET
    @Path("dir")
    @Produces({"text/plain","application/xml","application/json"})
    @Consumes({ "application/xml", "application/json",
    "application/x-www-form-urlencoded" })
    public String getLog(){
    ShowDirectory status = new ShowDirectory();
    return status.showDir();


    }
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Exposing command line directory list as REST API shows blank page

    It MIGHT help to know what exactly this "ShowDirectory" thing is, I don't recognize it. You can also, obviously, add some debugging to your code, such as a few system.out.println commands (and look at the logs to see the results) showing what directory "status" is looking at and then showing what "showDir" actually returns.

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

    Default Re: Exposing command line directory list as REST API shows blank page

    Show directory is a class file which is returning cmd c: dir, using system.out.println command shows the correct output.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Exposing command line directory list as REST API shows blank page

    Why are you using a command line execution to do a directory listing? Why do you not simply use the file class? Also, I have STILL have no idea how that class works. If it is not doing it correctly, the entire program will simply hang as the buffer gets filled and so the command never finishes.

Similar Threads

  1. Replies: 4
    Last Post: 01-02-2013, 08:50 PM
  2. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  3. Replies: 4
    Last Post: 10-31-2010, 05:19 PM
  4. Having trouble with printing a blank line.
    By Meta in forum New To Java
    Replies: 4
    Last Post: 05-11-2010, 10:54 PM
  5. Replies: 4
    Last Post: 07-20-2007, 04:18 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
  •