Reputation: 1140
In programmatic usage of CLI commands (in Java on Linux), would you
Different for "standard" commands, e.g. "ls", vs. non-standard commands?
Addendum: By "in the code" I didn't mean "hard-coded". Having the the commands' paths configurable would be of course the way to go.
Upvotes: 0
Views: 68
Reputation: 46965
If the absolute path is a standard path like in /usr/bin, /usr/sbin etc I would use those, otherwise I would do a which on the command name and use the output of that.
Upvotes: 0
Reputation: 272257
Neither(!). I'd provide a configuration, which may be as trivial as a properties file.
e.g.
command.ls = /bin/ls
etc. The above is straightforward to implement, and very easy to change/override as required. I would be wary of relying on the PATH for all but the simplest scenarios.
Upvotes: 4