博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Runtime.getRuntime().exec学习记录[转贴]

Posted on 2010-12-03 16:33  BradyChen  阅读(13553)  评论(0编辑  收藏  举报

原帖:http://chenyaqiong81081.blog.163.com/blog/static/44622594200791235256255/

一、Runtime.getRuntime().exec()执行命令情况:
       Runtime.getRuntime().exec("cmd /c your command")//2000
       Runtime.getRuntime().exec("command /c your command")//98
       Runtime.getRuntime().exec("sh/ your command")//linux

二、执行.sh文件的情况:
      1、把命令写成a.sh ;执行命令的时候
           Process child = Runtime.getRuntime().exec("bash a.sh,null,new File("//usr/local/mysql/bin/"));
           child.waitFor();
           ........
       2、Process child = Runtime.getRuntime().

                                          exec(new String[] {"/bin/sh","-c","mysqldump -u root -p7788919 axtic_cg" },

                                                   null,
                                                   new File("/usr/local/mysql/bin/"));
            child.waitFor();

            注:waitFor()等待操作完成