how to test for a dependency

Discussion in 'Python' started by Darren Dale, Jan 9, 2006.

  1. Darren Dale

    Darren Dale Guest

    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
     
    Darren Dale, Jan 9, 2006
    #1
    1. Advertising

  2. 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
     
    Dennis Benzinger, Jan 9, 2006
    #2
    1. Advertising

  3. 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
     
    Sybren Stuvel, Jan 9, 2006
    #3
  4. Darren Dale

    Darren Dale Guest

    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'
     
    Darren Dale, Jan 9, 2006
    #4
  5. Darren Dale

    Darren Dale Guest

    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.
     
    Darren Dale, Jan 9, 2006
    #5
  6. 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
     
    Steven Bethard, Jan 10, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sting
    Replies:
    5
    Views:
    1,662
    Natty Gur
    Jun 8, 2004
  2. Robert Allan Schwartz
    Replies:
    7
    Views:
    397
    Marco Manfredini
    Aug 13, 2004
  3. Chris
    Replies:
    1
    Views:
    685
    Chris
    May 11, 2006
  4. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    766
    Skybuck Flying
    Oct 4, 2009
  5. Giovanni Azua

    cmake + google test: weirdo dependency

    Giovanni Azua, Oct 8, 2011, in forum: C++
    Replies:
    1
    Views:
    711
    Victor Bazarov
    Oct 8, 2011
Loading...

Share This Page