I'm launching external application from my ruby script
using %x{application_name}
I want to check if such application exists before launching.
To check it on linux I can parse "which application_name" command
output.
But what about windows platform? Is there any crossplatform solution
exists?
Regards,
arkadi4
Hi there.
You would usually check the $PATH environment variable on *nix systems, and %Path% on Windows.
In Ruby, that environment variable may be accessed through ENV['PATH']. The path is joined together by a path separator character (on Windows it is a semi-colon `;' and on *nix it is a colon `:'). You can get this separator in an OS depending way such as File::PATH_SEPARATOR.
I'm sure from here you get the idea. You must split the path into each directory and perform an iterative operation, verifying the directory exists and if the program also exists in that directory.