check if application exists

A

Al Og

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
 
M

Matthew Harris

Al said:
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
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.
 
D

Daniel Berger

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?

require 'ptools'
File.which('ruby')

Yep, works on Windows.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top