blinlk182 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a script to run a program in another directory. The program is a PDF to HTML converter, it is located in a directory PDFtoHTML, and the command to run it is "pdftohtml file.pdf". The scripts i am using are outside of the PDFtoHTML directory, and I can't figure out how to run the program outside of its directory. Any suggestions?

Replies are listed 'Best First'.
Re: running files from other directories
by Zaxo (Archbishop) on Apr 16, 2005 at 20:15 UTC

    Put the directory in your $PATH or give system the full path to the script.

    system '/path/to/PDFtoHTML/pdftohtml', '/some/path/to/file.pdf' and die $?;

    After Compline,
    Zaxo

      To add to this - I usually use the full path or a relative path (I hate modifying the PATH). I find that FindBin and File::Spec are incredibly useful for this.

      use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, 'lib'); # get modules from t +he lib subdirectory under this perl script #... my $exe = File::Spec->catfile($FindBin::Bin, File::Spec->updir(), qw(PDFtoHTML pdftohtml)); system($exe, $pdffile) == 0 or do { # handle system error. }
Re: running files from other directories
by tlm (Prior) on Apr 16, 2005 at 20:10 UTC

    What's your OS? In Unix,

    % /path/to/pdftohtml file.pdf
    is usually sufficient. If you're trying to do this from within a script, then
    system '/path/to/pdftohmtl', 'file.pdf' and die "$?\n";

    the lowliest monk

Re: running files from other directories
by nimdokk (Vicar) on Apr 17, 2005 at 15:03 UTC
    Using the absolute path to the executable as others have mentioned is a good idea. Also, bear in mind that if you put the path into $PATH, and you run this script from cron, you will lose that PATH information. A good idea would be to use the full path the executable with the system command.