我想在Java中调用一个Linux下的可执行程序dmwrite,已经把这个dmwrite程序放在/usr/sbin目录下,手工执行了一下,没有问题,但在Java代码中通过Runtime.exec执行的时候却没有反应.
    后来我写了一个小shell:generate.sh,在这个sh中调用dmwrite,把shell文件放在了/home/test目录下面,java代码中这样执行exec("sh /home/test/generate.sh"),手工在linux的终端上这样执行没有问题,但是通过java代码执行总是没有反应,我这么些是不是有什么问题?对linux不怎么懂,期盼大家指教

解决方案 »

  1.   

    java里对LINUX路径的描述不一样吧
      

  2.   

    Process的标准输入流是需要接收完毕的,不然执行不会成功
    下面是随便搜索过来的一点代码,作参考吧
       Runtime  runtime  =  Runtime.getRuntime();  
       Process  process  =null;  
       String  line=null;  
       InputStream  is  =null;  
       InputStreamReader  isr=null;  
       BufferedReader  br  =null;  
       String  ip="www.sina.com.cn";  //待Ping的地址
        try  
       {  
           process  =runtime.exec("ping  "+ip);  
           is  =  process.getInputStream();  
           isr=new  InputStreamReader(is);  
           br  =new  BufferedReader(isr);  
           out.println("<pre>");  
           while(  (line  =  br.readLine())  !=  null  )  
           {  
               out.println(line);  
               out.flush();  
           }  
           out.println("</pre>");  
           is.close();  
           isr.close();  
           br.close();  
       }  
       catch(IOException  e  )  
       {  
           out.println(e);  
           runtime.exit(1);  
       }