在 mac 至 java 中打开终端
Opening terminal in mac through java
我正在使用以下代码在 windows 中打开 cmd 并执行 cd 命令,它对我来说工作正常。
Process p = Runtime.getRuntime().exec("cmd /c \" cd C:\Users"");
我想通过打开控制台在 mac 中做同样的事情,那么我应该写什么而不是 cmd ?
您需要 运行 使用 bash
可执行文件,如下所示:
String[] args = new String[] {"/bin/bash", "-c", "your_command", "with", "args"};
Process proc = new ProcessBuilder(args).start();
关注这个link:
我正在使用以下代码在 windows 中打开 cmd 并执行 cd 命令,它对我来说工作正常。
Process p = Runtime.getRuntime().exec("cmd /c \" cd C:\Users"");
我想通过打开控制台在 mac 中做同样的事情,那么我应该写什么而不是 cmd ?
您需要 运行 使用 bash
可执行文件,如下所示:
String[] args = new String[] {"/bin/bash", "-c", "your_command", "with", "args"};
Process proc = new ProcessBuilder(args).start();
关注这个link: