1

I have written a script to execute files one by one by calling a installed program. The same program is executing from terminal, like procheck abc.pdb, then it's working fine. But when I execute this program in a Perl script like

#!/usr/bin/perl -w
@proc = glob '*.pdb';

foreach $proc (@proc)

{
     system ('procheck $proc 2.0');
}

Getting error

sh: 1: procheck: not found 
  • have you tried specifying the full path to procheck ? – LinuxSecurityFreak Nov 9 '17 at 9:50
2

There are two things that might be issues here. First, with the single-quoted string, the variable is not expanded, so the system() call sees the literal string procheck $proc 2.0. Since it contains a character special to the shell (the $), Perl runs the command through the shell, so the shell gets a chance to expand that. Unless your environment contains the variable proc, that will expand to nothing. But that doesn't matter much, since the shell can't even seem to find the program procheck in the PATH. It complains about that.

If we change the quotes to double-quotes, the variable gets expanded by Perl (which is probably what you want, since you're using that variable in the loop). But then you're likely get a warning from Perl about not being able to find procheck.

The solution to that is to give the full path to the program, or make sure it's in the scripts PATH.

Though if running it on an interactive shell works, it's possible that procheck is actually an alias or a function. If it's just a regular executable, it would be in the PATH, which should be inherited to Perl and the subshell. In e.g. Bash, you could use type -a procheck to see what it actually runs and if there are other alternatives, like a disk file masked behind an alias.


Oh, also, if you don't need the shell when running the command, you can prevent Perl from even accidentally calling it by using the list form of system and giving the arguments to the command as separate arguments to system. Here, that would be system("procheck", $proc, "2.0").

0

The problem is you're using single quotes.

Try this instead...

system ("procheck $proc 2.0");
  • 1
    If the system() function can't find the procheck executable with double quotes, then it won't find it with single quotes either. This is not the problem that he OP is (currently) facing, but you're correct in that double quotes should be used to allow Perl to expand the $proc scalar. – Kusalananda Nov 9 '17 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.