当前位置: 代码迷 >> Java Web开发 >> 跪求 JAVA调用 SHELL脚本的有关问题
  详细解决方案

跪求 JAVA调用 SHELL脚本的有关问题

热度:617   发布时间:2016-04-17 12:54:10.0
跪求 JAVA调用 SHELL脚本的问题
Writer   writer   =   null;  
        String   filePath   =   null;  
        try{  
filePath   =   "/path/ ";  
writer   =   new   BufferedWriter(new   FileWriter(new   File(filePath   +   "export.sh ")));  
        }catch(Exception   e)   {  
        }  

        try   {  
                writer.write( "gzip   transums_file.del;\n ");  
                if   (writer   !=   null)   {  
                        writer.close();  
                }  
                }   catch   (Exception   e)   {  
                }  
String   cmd   =   "sh   "   +   filePath   +   "export.sh ";  
                try  
                {  
                        String   outStr   =   " ";  
                        //   执行CMD;  
                        Process   p   =   Runtime.getRuntime().exec(cmd);  
                        p.waitFor();  
                        InputStream   processIn   =   p.getInputStream();  
                        if   (processIn   !=   null){  
                                for   (int   ch   =   0;(ch   =   processIn.read())   !=   -1;){  
                                        outStr   +=   (char)   ch;  
                                }  
                        }  
                        out.println(outStr);  
                }catch(Exception   e){  
                        out.println(e.toString());  
                }  
上面这一段脚本调用死活不起作用  

前面一段生成的脚本   在命令行执行一点问题没有  

但用Runtime.getRuntime().exec(cmd);调用就不起作用   求大家帮忙看看   谢了

------解决方案--------------------
Runtime.getRuntime().exec(cmd); exec(cmd)不用这样写吗exce(cmd.exe)吗
我没试过,但以前写好像要扩展名的,嘿嘿
  相关解决方案