简体   繁体   中英

FireFox.exe path as per the operating system

How could we identify the installation path of firefox.exe using java code.

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

Here I am passing windows complete firefox.exe path.

Right now i am executing these command in Java, using

      Process p = Runtime.getRuntime().exec(parts);

Is there any way through which we can identify the location of

firefox.exe

as per the operating system.

Since you tagged the question as 'unix', on a Unix / Linux / MacOSX system, you can do this from the command line using the which command; eg

$ which firefox
/usr/bin/firefox

So, to do the same in Java, you can use a Process to run that command, and read the output into a string. It is also possible to do the same thing by reading the $PATH environment variable, splitting it, and checking each of the directories on the path to see if they contain a "firefox" executable. (You could probably do the same thing on Windows).

BTW, executables on Unix / Linux / MacOSX do not have a ".exe" file suffix. The ".exe" suffix is a Windows-ism.

This is not java-specific. On unix systems (and DOS shells) the general contract of locating an executable is as follows:

  1. get the PATH environment variable
  2. split it by the path separator character
  3. consider each split result as a directory
  4. check whether it contains an executable file with the name you're looking for.

At least that's what's used on the CLI. Desktop environments may use separate application registries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM