# Check if application exists

**URL:** <https://www.ruby-forum.com/t/check-if-application-exists/123851>\
**Category:** Ruby\
**Created:** [December 21, 2007, 10:23am UTC](https://www.ruby-forum.com/t/check-if-application-exists/123851 "2007-12-21T10:23:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkadi4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@arkadi4](https://www.ruby-forum.com/u/arkadi4)\
**Post date:** [December 21, 2007, 10:23am UTC](https://www.ruby-forum.com/t/check-if-application-exists/123851/1 "2007-12-21T10:23:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arkadi4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@arkadi4](https://www.ruby-forum.com/u/arkadi4)\
**Post date:** [December 21, 2007, 10:43am UTC](https://www.ruby-forum.com/t/check-if-application-exists/123851/2 "2007-12-21T10:43:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![arkadi4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@arkadi4](https://www.ruby-forum.com/u/arkadi4)\
**Post date:** [December 21, 2007, 11:29am UTC](https://www.ruby-forum.com/t/check-if-application-exists/123851/3 "2007-12-21T11:29:49Z")

</div>

Thanks Matthew, I got the idea.

---

<div class="post-metadata">

**Author:** ![arkadi4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@arkadi4](https://www.ruby-forum.com/u/arkadi4)\
**Post date:** [December 21, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/check-if-application-exists/123851/4 "2007-12-21T22:46:03Z")

</div>

On Dec 21, 4:29 am, Al Og [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![arkadi4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@arkadi4](https://www.ruby-forum.com/u/arkadi4)\
**Post date:** [December 21, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/check-if-application-exists/123851/5 "2007-12-21T23:23:32Z")

</div>

On Dec 21, 2:23 am, Al Og [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

Yep, works on Windows.

Regards,

Dan
