【发布时间】:2012-07-27 05:10:19
【问题描述】:
是否可以打开终端窗口并从 java 窗口执行某些命令?
我试过了
Runtime.getRuntime().exec("<command to execute>");
但它没有用。没有打开任何终端窗口。
(在 Windows、Mac 等...我需要多操作系统的解决方案)
【问题讨论】:
是否可以打开终端窗口并从 java 窗口执行某些命令?
我试过了
Runtime.getRuntime().exec("<command to execute>");
但它没有用。没有打开任何终端窗口。
(在 Windows、Mac 等...我需要多操作系统的解决方案)
【问题讨论】:
您需要针对每个操作系统的解决方案:
Runtime.getRuntime.exec("/usr/bin/open -a Terminal /path/to/the/executable");
Runtime.getRuntime.exec("/usr/bin/xterm");
Windows(不确定):
进程 p = Runtime.getRuntime().exec("cmd /c start cmd.exe"); p.waitFor();
【讨论】:
/path/to/executable 是一个带参数的命令怎么办。如何传递参数?