-1

次のコマンド ライン ディレクトリ リストをプレーン テキストの RestApi として公開しようとしています。system.out.println を使用してコンソールに c ディレクトリのリストを出力しますが、URI ページに出力を表示しません。例:

    http://localhost:Project/show/dir

は空白です。どこが間違っているかについての提案。以下はコードスニペットです。

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;
StringBuffer directory= new StringBuffer();
                                                     while((line=input.readLine()) != null) {
directory.append(line+ "\n");

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

サービス クラス:

@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();


}
}
4

1 に答える 1

1

showDir から null を返しています。すべての出力が標準出力に送信されています。

于 2013-10-01T20:14:22.107 に答える