C
C#•3y ago
Pokey

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
canton7
canton7•3y ago
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 like
Pokey
PokeyOP•3y ago
Hmm, I had considered executing but wanted to avoid. I suppose it only happens at startup, and doesn't have any ill effects
canton7
canton7•3y ago
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
Pokey
PokeyOP•3y ago
I'll have to parse the version output for that but yea, I guess so! Thanks
canton7
canton7•3y ago
But, splitting and searching PATH should be easy as well
Pokey
PokeyOP•3y ago
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!
Want results from more Discord servers?
Add your server