tags:

views:

74

answers:

1

I have this command that I load (example.sh) works well in the unix command line.

However, if I execute it in Perl using the system or ` syntax, it doesn't work. I am guessing certain settings like environment variables and other external sh files weren't loaded.

Is there an example coding to ensure it will work?

More Updates on coding execution failure (I have been trying with different codes):

push (@JOBSTORUN, "cd $a/$b/$c/$d; loadproject cats; sleep 60;");      
...
my $pm = new Parallel::ForkManager(3);

foreach my $job (@JOBSTORUN) {
    $pm->start and next;
    print(`$job`); 
    $pm->finish;
}

print "\n\n[DONE] FINISHED EXECUTING JOBS\n";

Output Messages:

sh: loadproject: command not found
+5  A: 

Can you show us what you have tried so far? How are you running this program?

My first suspicion wouldn't be the environment if you are running it from a login shell. any Perl script you start (well, any program, really) inherits the same environment. However, if you are running the program through cron, then that's a different story.

The other mistakes I usually make in these situations is specifying the relative paths incorrectly. The paths are fine from the command line, but my Perl script has some other current working directory.

For general advice, see Interact with the system when Perl isn't enough. There's also a chapter in Learning Perl about this.

That's about the best advice you can hope for given the very limited information you've shared with us.

brian d foy
thanks, i had limited information as i was thinking from home
Gordon
after more investigation, i discovered the command i was referencing was not the absolute path. Additionally, it was alias to a different command with some additional eval csh statements. thanks for your help!
Gordon
Yes, always use the full path to the command you want so you know exactly what you are getting. I talk about this in _Mastering Perl_ in the security chapter, but it's also good in the non-malicious cases. :)
brian d foy