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

  

相关文章:

  • 2021-04-21
  • 2022-12-23
  • 2021-11-15
  • 2021-06-12
  • 2022-02-15
  • 2022-02-04
  • 2021-12-23
猜你喜欢
  • 2021-12-24
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2021-05-30
  • 2021-12-19
  • 2021-04-21
相关资源
相似解决方案