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

I have aperl script that does a series of processing and if a condition is met it executes a shell script. The shell script and the perl module live in the same directory location. However, I get the following error with its call. I have also tried a chdir before the shell script is executed and provide the path+shell_script (/dir/shell.sh)but the same error message every time.</P

Can't exec "sh": No such file or directory at ../home/lib/dirA/perl_script.pm line 91 (#1) (W exec) A system(), exec(), or piped open call could not execute the named program for the indicated reason. Typical reasons include: the permissions were wrong on the file, the file wasn't found in $ENV{PATH}, the executable in question was compiled for another architecture, or the #! line in a script points to an interpreter that can't be run for similar reasons. (Or maybe your system doesn't suppo +rt #! at all.)

shell script

chdir "/home/lib/dirA/"; system("sh shell_script.sh");

I got curious so I built a simple perl script with only one command to call the same shell script and it completes without any error.

I have tried to research the warning errors but I have not found anything significant. Any insight is greatly appreciated.

Replies are listed 'Best First'.
Re: call a shell script from a perl script
by NetWallah (Canon) on Jan 15, 2014 at 16:34 UTC
    Alternatively, use the "full path" to sh, and the target command. use "-c" to parse from the command options (instead of from the standard input).

    These are standard "sh" parameters, nothing to do with perl.

    system("/bin/sh -c /bin/uname -a")
    Update::

    To properly pass the "-a" parameter to uname above, the command needs to be written as :

    system("/bin/sh -c \"/bin/uname -a\"") ; # or (more readable): system(qq(/bin/sh -c "/bin/uname -a"))

            If your eyes hurt after you drink coffee, you have to take the spoon out of the cup.
                  -Norm Crosby

      Awesome! Using the full path to the sh worked. Thank you very much your help. Appreciate!
      Posting what worked out for someone who may have similar issue.

      "/bin/sh shell_script.sh"
Re: call a shell script from a perl script
by toolic (Bishop) on Jan 15, 2014 at 15:02 UTC
    Show your shell script. Does it have a shebang line (#!/bin/sh)? If so, you can probably omit the sh in the system call:
    chdir "/home/lib/dirA/"; system("shell_script.sh");