check if application exists

Discussion in 'Ruby' started by Al Og, Dec 21, 2007.

  1. Al Og

    Al Og Guest

    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-forum.com/.
    Al Og, Dec 21, 2007
    #1
    1. Advertising

  2. 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://matthewharris.org
    Matthew Harris, Dec 21, 2007
    #2
    1. Advertising

  3. Al Og

    Al Og Guest

    Al Og, Dec 21, 2007
    #3
  4. Al Og

    Guest

    On Dec 21, 4:29 am, Al Og <> 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
    , Dec 21, 2007
    #4
  5. On Dec 21, 2:23=A0am, 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?


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

    Yep, works on Windows.

    Regards,

    Dan
    Daniel Berger, Dec 21, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Onur Bozkurt

    Check if e-mail exists...

    Onur Bozkurt, Aug 29, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    27,256
    php-dev
    Apr 19, 2009
  2. Quentin Huo

    How to check if a control exists?

    Quentin Huo, May 29, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    15,157
    Dan Brussee
    May 29, 2004
  3. Totan
    Replies:
    0
    Views:
    939
    Totan
    Apr 17, 2006
  4. Jason Stacy
    Replies:
    2
    Views:
    4,683
    Roedy Green
    Apr 27, 2008
  5. Ulf Meinhardt
    Replies:
    8
    Views:
    6,143
Loading...

Share This Page