开发者

Why doesn't my shell script work when I run it from Perl?

开发者 https://www.devze.com 2023-01-17 04:13 出处:网络
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 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 wil开发者_如何学JAVAl 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消