Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > portable testing for external programs

Reply
Thread Tools

portable testing for external programs

 
 
Lars Madsen
Guest
Posts: n/a
 
      10-11-2005

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)
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-11-2005
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/cl...uidelines.html
 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      10-11-2005
"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
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-11-2005
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/cl...uidelines.html
 
Reply With Quote
 
Lars Madsen
Guest
Posts: n/a
 
      10-11-2005
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
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-11-2005
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/cl...uidelines.html
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      10-11-2005
"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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing string from python programs to external programs lone_eagle Python 3 05-26-2009 09:16 PM
Portable way of testing if a function exist mathieu C Programming 6 12-29-2008 05:38 AM
Portable Python - free portable development environment ! perica.zivkovic@gmail.com Python 7 01-13-2007 11:19 AM
tools for creating small, practical and portable programs Andrzej C++ 0 11-14-2006 12:37 PM
portable (VHDL) vs. non-portable (altera LPM) approaches to signed computations Eli Bendersky VHDL 1 03-01-2006 02:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57