Detect binary exists in environment PATH
Hi there!
I'm building an application which relies on FFMpeg and FFProbe binaries to be present and accessible in a directory in the system PATH.
This application will be working across multiple platforms, so on Windows, those binaries might just be dumped in a folder which is in the system PATH environment variable, and on Linux those binaries might be installed as part of a package, and again therefore placed into a directory which is included in the system PATH environment variable.
These binaries are prerequisite to my application working, so I would like to detect they are present when starting the application, so I may quit with an error if they do not.
The trouble is, using File.Exists("ffmpeg.exe") or File.Exists("ffmpeg") does not respect the system PATH (understandably!) so I am not sure how I can check these binaries are present?
6 Replies
IIRC you have to split PATH yourself and search through each directory? Another option is to just try executing
ffmpeg.exe
(with --version
or something), and see if you get an error - that will also catch permission problems and the likeHmm, I had considered executing but wanted to avoid. I suppose it only happens at startup, and doesn't have any ill effects
It also tells you whether it's an incompatible version, and it does nicely catch permission issues etc, so it's not the worst thing in the world IMO
I'll have to parse the version output for that but yea, I guess so!
Thanks
But, splitting and searching PATH should be easy as well
ffmpeg version 2022-10-30-git-ed5a438f05-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
Yea I don't think I'll bother parsing that 😅
Throws on not found though, as desired
I'll go down that route, thank you!