Processing调用了exe就意味着失去了跨平台。调用的过程是,先得到当前的runtime,然后调用runtime的exec()方法,在exec()传入的是字符串参数,这个参数很重要,该有空格的地方必须有空格,否则就不能正常调用。这个方法返回一个进程(progess)。
如:
调用ping命令:process = Runtime.getRuntime().exec( "cmd /c " + "ping"+" "+ip_host);
调用jad工具:Runtime.getRuntime().exec("jad.exe -o -d "+path2+" -s java "+path1);
代码如下:
void setup() { size(100, 100); noLoop(); } void draw() { openWinExe(); openExe(); } //用 Java 调用windows系统的exe文件,比如notepad,calc之类 public static void openWinExe() { Runtime rn = Runtime.getRuntime(); Process p = null; try { String command = "explorer"; p = rn.exec(command); } catch (Exception e) { System.out.println("Error win exec!"); } } //调用其他的可执行文件,例如:自己制作的exe,或是 下载 安装的软件. public static void openExe() { Runtime rn = Runtime.getRuntime(); Process p = null; try { p = rn.exec(""C:/Windows/System32/winver.exe"); } catch (Exception e) { System.out.println("Error exec!"); } }