[26338] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8513 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 11 18:05:28 2005

Date: Tue, 11 Oct 2005 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 11 Oct 2005     Volume: 10 Number: 8513

Today's topics:
        portable testing for external programs <daleif@RTFSIGNATUREimf.au.dk>
    Re: portable testing for external programs <1usa@llenroc.ude.invalid>
    Re: portable testing for external programs <sherm@dot-app.org>
    Re: portable testing for external programs <1usa@llenroc.ude.invalid>
    Re: portable testing for external programs <daleif@RTFSIGNATUREimf.au.dk>
    Re: portable testing for external programs <1usa@llenroc.ude.invalid>
    Re: portable testing for external programs <sherm@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 11 Oct 2005 21:58:20 +0200
From: Lars Madsen <daleif@RTFSIGNATUREimf.au.dk>
Subject: portable testing for external programs
Message-Id: <434c1635$0$7637$ba624c82@nntp02.dk.telia.net>


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)


------------------------------

Date: Tue, 11 Oct 2005 20:53:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: portable testing for external programs
Message-Id: <Xns96ECABDBD8FEFasu1cornelledu@127.0.0.1>

Lars Madsen <daleif@RTFSIGNATUREimf.au.dk> wrote in
news:434c1635$0$7637$ba624c82@nntp02.dk.telia.net: 

> 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 <1usa@llenroc.ude.invalid>
(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


------------------------------

Date: Tue, 11 Oct 2005 17:04:52 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: portable testing for external programs
Message-Id: <m2ek6repe3.fsf@Sherm-Pendleys-Computer.local>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> 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


------------------------------

Date: Tue, 11 Oct 2005 21:10:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: portable testing for external programs
Message-Id: <Xns96ECAEAADE8B5asu1cornelledu@127.0.0.1>

Sherm Pendley <sherm@dot-app.org> wrote in
news:m2ek6repe3.fsf@Sherm-Pendleys-Computer.local: 

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> 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 <1usa@llenroc.ude.invalid>
(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


------------------------------

Date: Tue, 11 Oct 2005 23:31:00 +0200
From: Lars Madsen <daleif@RTFSIGNATUREimf.au.dk>
Subject: Re: portable testing for external programs
Message-Id: <434c2bec$0$7637$ba624c82@nntp02.dk.telia.net>

A. Sinan Unur wrote:
> Lars Madsen <daleif@RTFSIGNATUREimf.au.dk> wrote in
> news:434c1635$0$7637$ba624c82@nntp02.dk.telia.net: 
> 
> 
>>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


------------------------------

Date: Tue, 11 Oct 2005 21:39:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: portable testing for external programs
Message-Id: <Xns96ECB3ABE54EEasu1cornelledu@127.0.0.1>

Lars Madsen <daleif@RTFSIGNATUREimf.au.dk> wrote in
news:434c2bec$0$7637$ba624c82@nntp02.dk.telia.net: 

> A. Sinan Unur wrote:
>> Lars Madsen <daleif@RTFSIGNATUREimf.au.dk> wrote in
>> news:434c1635$0$7637$ba624c82@nntp02.dk.telia.net: 
>> 
>> 
>>>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 <1usa@llenroc.ude.invalid>
(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


------------------------------

Date: Tue, 11 Oct 2005 17:46:46 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: portable testing for external programs
Message-Id: <m2wtkj916h.fsf@Sherm-Pendleys-Computer.local>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> 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


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8513
***************************************


home help back first fref pref prev next nref lref last post