如何使用java代码识别firefox.exe的安装路径。
accumulator = (accumulator) && (runCommand("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "-P PAX-PROFILE-1 %s", "google"));
accumulator = (accumulator) && (runCommand("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "-P PAX-PROFILE-2 %s", "google"));
accumulator = (accumulator) && (runCommand("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "-P PAX-PROFILE-3 %s", "google"));
这里我传递 Windows 完整的 firefox.exe 路径。
现在我正在 Java 中使用
执行这些命令 Process p = Runtime.getRuntime().exec(parts);
有什么办法可以确定我们的位置
firefox.exe
根据操作系统。
最佳答案
由于您将问题标记为“unix”,因此在 Unix/Linux/MacOSX 系统上,您可以使用 which
命令从命令行执行此操作;例如
$ which firefox
/usr/bin/firefox
因此,要在 Java 中执行相同的操作,您可以使用 Process
来运行该命令,并将输出读入字符串中。还可以通过读取 $PATH
环境变量、拆分它并检查路径上的每个目录以查看它们是否包含“firefox”可执行文件来执行相同的操作。 (您可能可以在 Windows 上执行相同的操作)。
顺便说一句,Unix/Linux/MacOSX 上的可执行文件没有“.exe”文件后缀。 “.exe”后缀是 Windows 主义。
关于java - FireFox.exe 路径(根据操作系统),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37255102/