Jump to content

How do I verify if an EXE is in my Windows PATH?


Recommended Posts

QUOTE (normandinf @ Nov 25 2008, 05:05 PM)

But that only gets me the contents of the PATH environment variable.

I'm talking about something like the following example of which in the OS X Terminal:

[18:58:35]$ which curl/opt/local/bin/curl

It returns the path to the curl binary. If curl isn't in the user's path (for instance, if it's not installed in the system), it returns nothing.

Obviously I could take the results of the VI you posted and list the directories recursively until I've either exhausted everything or found what I'm looking for, but I'm hoping there's a less brute-force solution than that.

Link to comment

QUOTE (Justin Goeres @ Nov 25 2008, 10:49 PM)

But that only gets me the contents of the PATH environment variable.

I'm talking about something like the following example of which in the OS X Terminal:

[18:58:35]$ which curl/opt/local/bin/curl

It returns the path to the curl binary. If curl isn't in the user's path (for instance, if it's not installed in the system), it returns nothing.

Obviously I could take the results of the VI you posted and list the directories recursively until I've either exhausted everything or found what I'm looking for, but I'm hoping there's a less brute-force solution than that.

I thought the Windows equivalent "which" function was doing a recursive search too. I'm no expert on that, so I'll have to pass.

<guilty>I never even worked on Mac or Linux...</guilty>

Link to comment

QUOTE (Justin Goeres @ Nov 26 2008, 06:22 AM)

It probably is ;).

I just don't want to implement it myself if there's a better way. However, posting/Googling/yelling/crying haven't yet produced a solution :P.

why would it need to be recursive? the OS doesn't recurse down those paths. Just test all the paths in the environment variable and you're done.

If you're trying to run the EXE, you can always just run it and if it works, great, if not, you handle the error from System Exec and branch off into whatever you had planned to do if "which" had returned nothing. (I assume you already thought of this, but you never know).

Link to comment

QUOTE (Justin Goeres @ Nov 26 2008, 06:22 AM)

Perhaps this will help...

Several ports of Which are available here. I think that the first one demonstrates how to use the For Loop expansion variables ("%~"), so you could probably just extract out that piece and call a one-liner directly via System Exec.vi.

Link to comment

QUOTE (jdunham @ Nov 26 2008, 09:15 AM)

why would it need to be recursive? the OS doesn't recurse down those paths. Just test all the paths in the environment variable and you're done.

It's not recursive? Hmmph. I always assumed it was. That does simplify it.

QUOTE

If you're trying to run the EXE, you can always just run it and if it works, great, if not, you handle the error from System Exec and branch off into whatever you had planned to do if "which" had returned nothing. (I assume you already thought of this, but you never know).

Ya, that's an interesting thing. Turns out the program I'm looking at doing this with shows its "About" dialog if you call it with either no arguments or invalid arguments. So that's delightfully unhelpful :P. For 99% of the other command-line utilties in the world, that would work.

Link to comment

QUOTE (Justin Goeres @ Nov 26 2008, 02:43 PM)

Turns out the program I'm looking at doing this with shows its "About" dialog if you call it with either no arguments or invalid arguments. So that's delightfully unhelpful :P. For 99% of the other command-line utilties in the world, that would work.

Does the EXE have a benign argument/mode such as /?, /help, /version, etc. that just shows the help or version information?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.