Justin Goeres Posted November 26, 2008 Report Share Posted November 26, 2008 On Windows, is there a(n easy) way to verify if a given EXE is in my user's PATH? I'm looking for something similar to which on Unix/Linux. I know there's an actual Windows port of which, but that's not what I mean. I'm looking for something built-in that I can run via System Exec.vi (or other magic). Quote Link to comment
Francois Normandin Posted November 26, 2008 Report Share Posted November 26, 2008 QUOTE (Justin Goeres @ Nov 25 2008, 07:00 PM) On Windows, is there a(n easy) way to verify if a given EXE is in my user's PATH? I'm looking for something similar to which on Unix/Linux.I know there's an actual , but that's not what I mean. I'm looking for something built-in that I can run via System Exec.vi (or other magic). There's a function in kernel32.dll to get the list of environment variables. (GetEnvironmentVariableA) Download File:post-10515-1227661495.zip (saved for LV 8.5) Quote Link to comment
Justin Goeres Posted November 27, 2008 Author Report Share Posted November 27, 2008 QUOTE (normandinf @ Nov 25 2008, 05:05 PM) There's a function in kernel32.dll to get the list of environment variables. (http://msdn.microsoft.com/en-us/library/ms683188.aspx' rel='nofollow' target="_blank">GetEnvironmentVariableA) 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. Quote Link to comment
Francois Normandin Posted November 27, 2008 Report Share Posted November 27, 2008 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> Quote Link to comment
Justin Goeres Posted November 27, 2008 Author Report Share Posted November 27, 2008 QUOTE (normandinf @ Nov 26 2008, 05:58 AM) I thought the Windows equivalent "which" function was doing a recursive search too. 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 . Quote Link to comment
jdunham Posted November 27, 2008 Report Share Posted November 27, 2008 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 . 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). Quote Link to comment
orko Posted November 27, 2008 Report Share Posted November 27, 2008 QUOTE (Justin Goeres @ Nov 26 2008, 06:22 AM) 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 . 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. Quote Link to comment
Justin Goeres Posted November 27, 2008 Author Report Share Posted November 27, 2008 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 . For 99% of the other command-line utilties in the world, that would work. Quote Link to comment
Jim Kring Posted November 27, 2008 Report Share Posted November 27, 2008 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 . 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? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.