portable testing for external programs

Discussion in 'Perl Misc' started by Lars Madsen, Oct 11, 2005.

  1. Lars Madsen

    Lars Madsen Guest

    normally I only work on Linix systems, but now I have to write
    a test script (for some LaTeX stuff) that needs to be able to run on
    unix systems, MAC OS X and Windows.

    I need to test whether certain programs are available on a particular
    system. Say, we want to know if 'ps2pdf' exists on this system. How
    would you create a perl script that are able to run on Windows, Mac OS X
    and Linux, that will tell you if a given external program is available
    on this system?

    /daleif (remove RTFSIGNATURE for email)
    Lars Madsen, Oct 11, 2005
    #1
    1. Advertising

  2. Lars Madsen <> wrote in
    news:434c1635$0$7637$:

    > normally I only work on Linix systems, but now I have to write
    > a test script (for some LaTeX stuff) that needs to be able to run on
    > unix systems, MAC OS X and Windows.
    >
    > I need to test whether certain programs are available on a particular
    > system. Say, we want to know if 'ps2pdf' exists on this system. How
    > would you create a perl script that are able to run on Windows, Mac OS
    > X and Linux, that will tell you if a given external program is
    > available on this system?


    Do you want to find the binary in the path, or anywhere on the hard
    drive? If you only want to find it in the path, your task is simple:

    #!/usr/bin/perl

    use strict;
    use warnings;

    sub is_ps2pdf_in_path {
    my $s = `ps2pdf`;
    return ( -1 < index $s, 'Usage' );
    }

    printf "ps2pdf: %s\n",
    ( is_ps2pdf_in_path() ) ? 'found' : 'not found';

    __END__

    On the other hand, for more general usage, I would suggest a
    configuration dialog during installation asking the user to specify the
    locations of the binaries you need instead of searching the hard drive
    for possibly a very long time for each binary.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 11, 2005
    #2
    1. Advertising

  3. "A. Sinan Unur" <> writes:

    > On the other hand, for more general usage, I would suggest a
    > configuration dialog during installation asking the user to specify the
    > locations of the binaries you need instead of searching the hard drive
    > for possibly a very long time for each binary.


    You could do a quick scan of some common locations - /usr/bin, /usr/local/bin,
    /opt/bin, /opt/local/bin on *nix (including Mac OS X), /sw/bin on Mac OS X
    (Fink installs packages there), and c:/who/knows/ on Windows.

    If you find the binary you're looking for in one of those locations, you could
    provide that location as the default response in the dialog above.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Oct 11, 2005
    #3
  4. Sherm Pendley <> wrote in
    news::

    > "A. Sinan Unur" <> writes:
    >
    >> On the other hand, for more general usage, I would suggest a
    >> configuration dialog during installation asking the user to specify
    >> the locations of the binaries you need instead of searching the hard
    >> drive for possibly a very long time for each binary.

    >
    > You could do a quick scan of some common locations - /usr/bin,
    > /usr/local/bin, /opt/bin, /opt/local/bin on *nix (including Mac OS X),
    > /sw/bin on Mac OS X (Fink installs packages there), and c:/who/knows/
    > on Windows.


    $ENV{ProgramFiles} ;-)


    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 11, 2005
    #4
  5. Lars Madsen

    Lars Madsen Guest

    A. Sinan Unur wrote:
    > Lars Madsen <> wrote in
    > news:434c1635$0$7637$:
    >
    >
    >>normally I only work on Linix systems, but now I have to write
    >>a test script (for some LaTeX stuff) that needs to be able to run on
    >>unix systems, MAC OS X and Windows.
    >>
    >>I need to test whether certain programs are available on a particular
    >>system. Say, we want to know if 'ps2pdf' exists on this system. How
    >>would you create a perl script that are able to run on Windows, Mac OS
    >>X and Linux, that will tell you if a given external program is
    >>available on this system?

    >
    >
    > Do you want to find the binary in the path, or anywhere on the hard
    > drive? If you only want to find it in the path, your task is simple:
    >


    just in the path, need to make sure that it's there for later use

    > #!/usr/bin/perl
    >
    > use strict;
    > use warnings;
    >
    > sub is_ps2pdf_in_path {
    > my $s = `ps2pdf`;
    > return ( -1 < index $s, 'Usage' );
    > }
    >
    > printf "ps2pdf: %s\n",
    > ( is_ps2pdf_in_path() ) ? 'found' : 'not found';
    >
    > __END__
    >


    hmm, this doesn't even work on linux since just running 'ps2pdf' sends
    output to STDERR so $s is empty.

    Another problem with this way is programs that does not terminate
    'latex' is one example. It does not terminate properly if not given
    something to work on.

    The best thing may be to simply search through the PATH variable (and
    perhaps possible aliases. Just found a File::Which module that, who code
    one could be inspired by. Will look into that later.



    /daleif
    Lars Madsen, Oct 11, 2005
    #5
  6. Lars Madsen <> wrote in
    news:434c2bec$0$7637$:

    > A. Sinan Unur wrote:
    >> Lars Madsen <> wrote in
    >> news:434c1635$0$7637$:
    >>
    >>
    >>>normally I only work on Linix systems, but now I have to write
    >>>a test script (for some LaTeX stuff) that needs to be able to run on
    >>>unix systems, MAC OS X and Windows.
    >>>
    >>>I need to test whether certain programs are available on a particular
    >>>system. Say, we want to know if 'ps2pdf' exists on this system. How
    >>>would you create a perl script that are able to run on Windows, Mac
    >>>OS X and Linux, that will tell you if a given external program is
    >>>available on this system?

    >>
    >>
    >> Do you want to find the binary in the path, or anywhere on the hard
    >> drive? If you only want to find it in the path, your task is simple:
    >>

    >
    > just in the path, need to make sure that it's there for later use
    >
    >> #!/usr/bin/perl
    >>
    >> use strict;
    >> use warnings;
    >>
    >> sub is_ps2pdf_in_path {
    >> my $s = `ps2pdf`;
    >> return ( -1 < index $s, 'Usage' );
    >> }
    >>
    >> printf "ps2pdf: %s\n",
    >> ( is_ps2pdf_in_path() ) ? 'found' : 'not found';
    >>
    >> __END__
    >>

    >
    > hmm, this doesn't even work on linux since just running 'ps2pdf' sends
    > output to STDERR so $s is empty.
    >
    > Another problem with this way is programs that does not terminate
    > 'latex' is one example. It does not terminate properly if not given
    > something to work on.


    In that case, you could try latex --help.

    I agree, this is tedious though.

    > The best thing may be to simply search through the PATH variable (and
    > perhaps possible aliases. Just found a File::Which module that, who
    > code one could be inspired by. Will look into that later.


    I did not know about File::Which. That looks like a good way to search
    the path in a fairly platform independent way. It does seem to do the
    right thing in Windows, it can also locate multiple copies. Cool.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 11, 2005
    #6
  7. "A. Sinan Unur" <> writes:

    > I did not know about File::Which. That looks like a good way to search
    > the path in a fairly platform independent way. It does seem to do the
    > right thing in Windows, it can also locate multiple copies. Cool.


    A shame it's not core. It would be damn useful in Makefile.PL's.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Oct 11, 2005
    #7
    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. Eli Bendersky
    Replies:
    1
    Views:
    1,161
    Mike Treseler
    Mar 1, 2006
  2. Replies:
    12
    Views:
    1,635
    Dave Thompson
    Jan 10, 2005
  3. Replies:
    7
    Views:
    914
  4. Andrzej
    Replies:
    0
    Views:
    274
    Andrzej
    Nov 14, 2006
  5. lone_eagle
    Replies:
    3
    Views:
    631
    psykeedelik
    May 26, 2009
Loading...

Share This Page