Check if application exists

Hello everyone,

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

Al Og wrote:

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.

Thanks Matthew, I got the idea.

On Dec 21, 4:29 am, Al Og [email protected] wrote:

Thanks Matthew, I got the idea.

Posted viahttp://www.ruby-forum.com/.

If the program writes to the windows registry you could also use that
to determine if the program is installed

Luis

On Dec 21, 2:23 am, Al Og [email protected] wrote:

exists?
require ‘ptools’
File.which(‘ruby’)

Yep, works on Windows.

Regards,

Dan