【发布时间】:2021-08-17 17:17:29
【问题描述】:
我知道使用在我的系统上正常运行的命令行在 mac 中获取 Edge、Firefox 和 Chrome 浏览器版本的命令。
Edge=/Applications/"Microsoft Edge.app"/Contents/MacOS/"Microsoft Edge" -version
FireFox=/Applications/Firefox.app/Contents/MacOS/firefox -v
Chrome=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
Chrome1=/Applications/"Google Chrome.app"/Contents/MacOS/"Google Chrome" --version
当我尝试使用 Firefox 时,它成功地返回了 Firefox 版本。 但是当我尝试使用 Edge 或 chrome 时,它会在 java 程序中引发错误。
Cannot run program "/Application/"Google" error=2 no such file or directory
我尝试将查询转义为/Applications/\"Microsoft Edge.app\"/Contents/MacOS/\"Microsoft Edge\" -version。我在作为查询传递之前打印相同的查询,如果我直接将它复制粘贴到终端上,我会得到完全相同的查询。
下面是代码sn-p
我错过了什么吗?
String line;
Process process;
String msEdgeVersion = null;
/*process = Runtime.getRuntime().exec("/Applications/Firefox.app/Contents/MacOS/firefox -v");*/
process = Runtime.getRuntime().exec(/Applications/"Microsoft Edge.app"/Contents/MacOS/"Microsoft Edge" -version);
// process = Runtime.getRuntime().exec("where notepad");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = br.readLine()) != null) {
if (!StringUtils.isBlank(line)) {
msEdgeVersion = line;
System.out.println(line);
}
}
process.waitFor();
process.destroy();
【问题讨论】:
标签: macos google-chrome firefox command-line microsoft-edge