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

Hi,

I have a call to another script using the exec() function but all it does it output an error :
Startup.cgi cannot exec "ComLine.pl": Exec error at line ... here is my code after trawling throught the catacombs, web, books etc:

my @args = ("$blastResult", "$oldRefFile", "@species_filter", "@chromo_filter", "@advanced_filter"); exec("ComLine.pl", @args);

Im sure i have the details right as i adjusted the code from another node: Exec function arguments

Any help is appreciated,
Cheers, MonkPaul.

Replies are listed 'Best First'.
Re: Exec() argument format
by eyepopslikeamosquito (Archbishop) on Jul 25, 2005 at 21:26 UTC

    It could be that ComLine.pl is not executable or not on your PATH. Assuming ComLine.pl is in your current working directory, you might try:

    exec($^X, "ComLine.pl", @args);
    where $^X is the name of the running perl interpreter (if ComLine.pl is not in your current working directory, use an absolute path instead).

    Update: You should also add a line something like:

    die "exec failed: $!";
    immediately after the exec line, because if the exec works you should not get to the next line.

      ok, thankyou

      but just for clarifictaion can you give me an example of $^X in use.

      cheers, MonkPaul.

        $^X is just a special variable, and it contains a string representing the full path to the current Perl interpreter. This is very helpful if you have more than one Perl installed.

        For example, try running the following:

        perl -e 'print $^X'

        On the Win32 machine I'm using here at work, with ActiveState Perl, this prints:

        C:\Perl\bin\perl.exe
        
        <-radiant.matrix->
        Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
        The Code that can be seen is not the true Code
        "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: Exec() argument format
by sacked (Hermit) on Jul 25, 2005 at 21:32 UTC
    Is ComLine.pl executable?

    What is the value of $! after the failed call?
    exec('ComLine.pl', @args ) or die "Can't exec: $!";
    Aside, you'll generally want to use system rather than exec because exec never returns. Instead, it replaces the currently running program with the program passed as the first parameter.

    If you have any code that follows the call to exec, you should use system instead.

    Please see perlfunc for details about the return values from exec and system.

    --sacked
      Ok, it says cannot execute - No such file or directory.
      ALthough im passing in the file off command line anyway.

      The ComLine.pl is executable. Im at a loss here.

      I was thinking of using system() but there is no code afterwards and im printing out to a web page in anothe file so i didnt want to lock anything.

        As suggested by eyepopslikeamosquito above, consider using the full path to the ComLine.pl program:
        exec( '/path/to/ComLine.pl', @args ) or die "exec: $!"
        or invoke the Perl interpreter ($^X, documented in perlvar), also suggested above.

        --sacked