0

Python 3 has the very useful shutil.which (https://docs.python.org/3/library/shutil.html#shutil.which) function. Is there an equivalent for Scala?

For context, I want to run a shell command in scala to get a notification to the user. For example, in the case of ubuntu, something like Seq("notify-send", title, msg) ! (using sys.process from the standard library). But I want to check beforehand if command is in the system path, so I can give an informative error message.

I'd like to avoid resorting to parsing (i.e. splitting on :) and iterating over the folders manually. Another alternative would be Seq("which", "command") !, but that doesn't work on windows (right?).

bobismijnnaam
  • 1,361
  • 2
  • 10
  • 20
  • Perhaps prox could help? https://vigoo.github.io/prox/docs/ – randbw Sep 15 '20 at 08:46
  • If this question is about Ammonite (or some other specific tool) you may have a higher change of getting a relevant answer by specifying that and adding the relevant tag(s). `!` is not built-in into Scala. – stefanobaghino Sep 15 '20 at 10:12
  • @stefanobaghino I have clarified my use case and (standard) library usage. @randbw It seems prox does not have `which`-like functionality, but maybe I missed it. – bobismijnnaam Sep 15 '20 at 18:41

0 Answers0