成就梦想

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  21 随笔 :: 22 文章 :: 6 评论 :: 0 Trackbacks

Windows下调用程序

Process proc =Runtime.getRuntime().exec("exefile");

Linux下调用程序就要改成下面的格式

Process proc =Runtime.getRuntime().exec("./exefile");

Windows下调用系统命令

String [] cmd={"cmd","/C","dir"};
Process proc =Runtime.getRuntime().exec(cmd);

Linux下调用系统命令就要改成下面的格式

String [] cmd={"/bin/sh","-c","ln -s exe1 exe2"};
Process proc =Runtime.getRuntime().exec(cmd);

Windows下调用系统命令并弹出命令行窗口

String [] cmd={"cmd","/C","start copy exe1 exe2"};
Process proc =Runtime.getRuntime().exec(cmd);

Linux下调用系统命令并弹出终端窗口就要改成下面的格式

String [] cmd={"/bin/sh","-c","xterm -e ln -s exe1 exe2"};
Process proc =Runtime.getRuntime().exec(cmd);

还有要设置调用程序的工作目录就要

Process proc =Runtime.getRuntime().exec("exeflie",null, new File("workpath"))ProcessBuilder ;


同理:
ProcessBuilder也可以这么使用管道 ,使用 |
    ProcessBuilder builder = new ProcessBuilder("/bin/sh","-c","ps aux |grep java");

posted on 2012-04-25 13:40 iamct 阅读(3644) 评论(0)  编辑  收藏 所属分类: 基础知识

只有注册用户登录后才能发表评论。


网站导航: