in reply to shell within system() call
As system always starts a new shell (or no shell at all, in case the command doesn't contain any shell metacharacters), the only way to make shell functions available is by sourcing the definitions in that new shell. And in case you need a ksh, you'll also want to start the shell yourself:
system('/bin/ksh', '-c', '. /env.ksh ; shellFunction');
Or, in case env.ksh is huge, and you want to avoid re-sourcing it every time, you could open a pipe to the shell, e.g.
my $pid = open my $shell, "| /bin/ksh" or die "Couldn't start ksh: $!" +; print $shell ". /env.ksh\n"; print $shell "shellFunction\n"; # later print $shell "shellFunction2\n"; # ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: shell within system() call
by shmem (Chancellor) on Mar 19, 2010 at 20:51 UTC | |
|
Re^2: shell within system() call
by claudius (Initiate) on Mar 22, 2010 at 20:55 UTC |