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");