java 调用linux脚本例子

public void startTomcat()
    {
        
        String currentPath = ServletActionContext.getServletContext()
                .getRealPath(File.separator + "WEB-INF" + File.separator);
        String tomcatBin = currentPath.split("webapps")[0] + "bin";
        String[] commands = {"sh", "startup.sh"};
        try
        {
            ProcessBuilder b = new ProcessBuilder(commands);
            b.redirectErrorStream();
            b = b.directory(new File(tomcatBin));
            Process rt = b.start();
            rt.waitFor();
        }
        catch (IOException e)
        {
        }
        catch (InterruptedException e)
        {
            
        }
       
    
    }

posted @ 2013-06-14 12:29  嗨,你的益达~~~  阅读(191)  评论(0编辑  收藏  举报