[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

check if application exists

Al Og

12/21/2007 9:23:00 AM

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
--
Posted via http://www.ruby-....

4 Answers

Matthew Harris

12/21/2007 9:42:00 AM

0

Al Og wrote:
> 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.

--
Matthew Harris
http://matthew...


Al Og

12/21/2007 10:30:00 AM

0


Thanks Matthew, I got the idea.
--
Posted via http://www.ruby-....

lrlebron@gmail.com

12/21/2007 9:41:00 PM

0

On Dec 21, 4:29 am, Al Og <arka...@gmail.com> wrote:
> Thanks Matthew, I got the idea.
> --
> Posted viahttp://www.ruby-....

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

Luis

Daniel Berger

12/21/2007 10:23:00 PM

0



On Dec 21, 2:23=A0am, Al Og <arka...@gmail.com> wrote:
> 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