473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to test for a dependency

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
Jan 9 '06 #1
5 1032
Darren Dale schrieb:
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
Jan 9 '06 #2
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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Jan 9 '06 #3
Dennis Benzinger wrote:
Darren Dale schrieb:
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.

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'

Jan 9 '06 #4
Sybren Stuvel wrote:
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".


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.
Jan 9 '06 #5
Darren Dale wrote:
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
Jan 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
5
by: Jay A. Moritz | last post by:
Error: The dependency '<my dll>' in project '<my project>' cannot be copied to the run directory because it would conflict with dependency '<my dll>'. I am getting a dependency error building...
3
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
9
by: Brett Romero | last post by:
I have two projects in one solution - a library and executable. Each have a namespace such as: ROOT.myapp.Functional ROOT.myapp.UI However, each cannot reference the other. myapp.UI is...
6
by: deanhiller | last post by:
In C++ or Java, or whatever OO, I am used to using the Dependency Injection Pattern(or I believe formerly called Inversion of Control Pattern) to accomplish test first in a large system. ie. I...
1
by: =?Utf-8?B?SmFzb24gUmljaG1laWVy?= | last post by:
I came across a code sample in a book that I am reading that uses a dependency property. I looked at some of the documentation for dependency properties but, for some reason, the concept is not...
1
by: vincentt | last post by:
Hi, We code DLL's and so far it was done using VS6.0. We are planning to migrate the VS.NET 2005 and use the VS6 VC++ code which generated the DLL to VS 2005 VC++.NET. However we donot plan to...
2
by: DeveloperX | last post by:
Hi, I'm struggling to work out how to unit test threading. Is there any advice out there? I'll take books, blogs and especially your experience. I can't be more specific, I just don't know how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.