<font color="#000000"><br></font><br><div class="gmail_quote">On Thu, Sep 20, 2012 at 5:06 PM, Gelonida N <span dir="ltr"><<a href="mailto:gelonida@gmail.com" target="_blank">gelonida@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'd like to implement the equivalent functionality of the unix command<br>
/usr/bin/which<br>
<br>
The function should work under Linux and under windows.<br>
<br>
Did anybody already implement such a function.<br>
If not, is there a portable way of splitting the environment variable PATH?<br></blockquote><div><br></div><div>I've used the following in programs I write:</div><div><br></div><div>def which(program):</div><div>   def is_exe(fpath):</div>

<div>      return os.path.exists(fpath) and os.access(fpath, os.X_OK)</div><div><br></div><div>   fpath, fname = os.path.split(program)</div><div>   if fpath:</div><div>      if is_exe(program):</div><div>         return program</div>

<div>   else:</div><div>      for path in os.getenv("PATH").split(os.pathsep):</div><div>         exe_file = os.path.join(path, program)</div><div>         if is_exe(exe_file):</div><div>            return exe_file</div>

<div>   return None</div><div><br></div><div>IIRC, I adapted it from StackOverflow.  I know it works on Linux and Mac OS X, but not sure about windows (since I don't know if PATH works the same way there).</div><div>
<br>
</div><div>HTH,</div><div>Jason</div><div><br></div></div>