#8474: Detect whether a program is in the path
-----------------------------+----------------------------------------------
Reporter: jhpalmieri | Owner: drkirkby
Type: defect | Status: needs_review
Priority: blocker | Milestone: sage-4.3.4
Component: porting | Keywords:
Author: John Palmieri | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
-----------------------------+----------------------------------------------
Changes (by jhpalmieri):
* status: needs_work => needs_review
Comment:
Here's a new patch which uses "command -v". On my mac, on sage.math, and
on t2.math, "type" and "command -v" behave essentially the same, more or
less like this:
{{{
sage: from subprocess import call, PIPE
sage: call('type ' + 'ls', shell=True, stdout=PIPE, stderr=PIPE) # note
the space in 'type '
0
sage: call('type ' + 'lljsdfs', shell=True, stdout=PIPE, stderr=PIPE)
1
sage: call('command -v ' + 'ls', shell=True, stdout=PIPE, stderr=PIPE)
0
sage: call('command -v ' + 'llkjsdfs', shell=True, stdout=PIPE,
stderr=PIPE)
127
}}}
The only difference on the platforms is the value of the nonzero return
code: sometimes it's 1, sometimes is 127, depending on the platform and
the command. It's always nonzero, though, when the program doesn't exist.
(With these arguments, the command "call" calls a program by passing to
the shell without printing standard output or standard error, and it
returns a code which is zero if the program exits correctly, nonzero
otherwise, and I think the return codes have something to do with the
system return codes, but they're not necessarily the same. See
[http://docs.python.org/library/subprocess.html#convenience-functions].)
Note that I don't care about the output of the functions, so your concern
about "type" in that regard is not a big deal. However, if "command -v"
is Posix standard, we can switch to that, since it seems to behave the
same way.
Regardless, I think you'll agree that it would be good to have one
portable way to do this, in one place in the Sage library, so functions
like "have_latex" and "have_chomp" will work right on Solaris, linux, Mac,
etc.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8474#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.