how to test for a dependency

D

Darren Dale

Hello,

I would like to test that latex is installed on a windows, mac or linux
machine. What is the best way to do this? This should work:

if os.system('latex -v'):
print 'please install latex'

but I dont actually want the latex version information to print to screen. I
tried redirecting sys.stdout to a file, but that doesnt help. Is there a
better way to do this in a cross-platform friendly way?

Thanks,
Darren
 
D

Dennis Benzinger

Darren said:
Hello,

I would like to test that latex is installed on a windows, mac or linux
machine. What is the best way to do this? This should work:

if os.system('latex -v'):
print 'please install latex'

but I dont actually want the latex version information to print to screen. I
tried redirecting sys.stdout to a file, but that doesnt help. Is there a
better way to do this in a cross-platform friendly way?

Thanks,
Darren


I didn't try it, but you could use the subprocess module
<http://python.org/doc/2.4.2/lib/module-subprocess.html>.
Create a Popen object with stdout = PIPE so that a pipe to the child
process is created and connected to the client's stdout.


Bye,
Dennis
 
S

Sybren Stuvel

Darren Dale enlightened us with:
I would like to test that latex is installed on a windows, mac or linux
machine. What is the best way to do this? This should work:

if os.system('latex -v'):
print 'please install latex'

The downside is that you can only use this to test by executing.
Perhaps it would be better to make a function that can search the PATH
environment variable in a cross-platform way. Also make sure you
include any platform-specific executable postfixes like Window's
".exe".

Sybren
 
D

Darren Dale

Dennis said:
I didn't try it, but you could use the subprocess module
<http://python.org/doc/2.4.2/lib/module-subprocess.html>.
Create a Popen object with stdout = PIPE so that a pipe to the child
process is created and connected to the client's stdout.


Thanks for the suggestion, that would probably work. Unfortunately, I need
to support Python 2.3 for some time to come.

I wonder, will this work across platforms?

if os.system('latex -v > temp.log'): print 'install latex'
 
D

Darren Dale

Sybren said:
Darren Dale enlightened us with:

The downside is that you can only use this to test by executing.
Perhaps it would be better to make a function that can search the PATH
environment variable in a cross-platform way. Also make sure you
include any platform-specific executable postfixes like Window's
".exe".

I guess that would work. I was hoping there was a more elegant, batteries
included way to do it.

By the way, great Zappa quote.
 
S

Steven Bethard

Darren said:
I would like to test that latex is installed on a windows, mac or linux
machine. What is the best way to do this? This should work:

if os.system('latex -v'):
print 'please install latex'

but I dont actually want the latex version information to print to screen. I
tried redirecting sys.stdout to a file, but that doesnt help. Is there a
better way to do this in a cross-platform friendly way?

I've been using Trent's which package[1] for this kind of thing:

import which
try:
latex = which.which('latex')
except which.WhichError:
print 'please install latex'


STeVe

[1] http://starship.python.net/crew/tmick/#which
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top