portable testing for external programs

L

Lars Madsen

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)
 
A

A. Sinan Unur

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
 
S

Sherm Pendley

A. Sinan Unur said:
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--
 
A

A. Sinan Unur

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
 
L

Lars Madsen

A. Sinan Unur said:
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
 
A

A. Sinan Unur

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


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
 
S

Sherm Pendley

A. Sinan Unur said:
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--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top