Steven Bethard wrote:
Hari Sekhon wrote:
  
I am writing a wrapper to a binary command to run it and then do 
something with the xml output from it.

What is the best way of making sure that the command is installed on the 
system before I try to execute it, like the python equivalent of the 
unix command "which"?
    

There is the which module:

     http://trentm.com/projects/which/

But I'd probably just try the command and catch the exception, e.g.:

 >>> import subprocess
 >>> try:
...     subprocess.call(['foo'])
... except OSError:
... 	print "you don't have foo installed"
...
you don't have foo installed
 >>> try:
...     subprocess.call(['svm_learn'])
... except OSError:
... 	print "you don't have svm_learn installed"
...
1

STeVe
  
looks good, although I agree with you on the try it and see simplicity. I think if the which.py was part of the standard lib then I would use it, but as it is I will stick to the original path search that you recommended (I'm not gonna both dealing with the pathext just yet)

-- 
Hari Sekhon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to