Max Spring
Max Spring

Reputation: 1140

PATH and programmatic usage?

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

Answers (2)

ennuikiller
ennuikiller

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

Brian Agnew
Brian Agnew

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

Related Questions