I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system()
, 'back ticks'
, exec()
and open()
)
I would like to run another PERL-script from first one, not exiting from the first one (as by exec()
), not catching the STDOUT
of the called script (as in the back tick
processing,) but having it printed out, as in initial script (as it is by system()
.)
I do not need the return status (as by system()
); but,
- I would like to have the called script to set some variables, that will be accessible in the calling script (sure by the
our @set_var;
)
My attempt (that I am not able to make do what I need) is:
...
if($condition)
{ local $0 = 'script2.pl';
local @ARGV = ('first-arg', 'second_arg');
do script2.pl;
}
print "set array is: '@set_var'\n";
...
The 'script2' would have something like:
#!/usr/bin/perl
...
print "having input parameters: '@ARGV'\n";
... # all script activities
our @set_var = ($val1, $val2, $val3);
exit 0;
The proble in my code is that the do ...
command is executing on beginning of the first script run and not in the place, where it is prepared for it (by set local ..
vars!)
I did try to use the eval "do script2.pl"
:
- now it is executed in the proper place, but it is not setting the
@set_var
into the first script process!
Is there any idea to do it as I would like to have it?
(I understand, that I can rewrite the script2.pl
as a function and load it by require()
and execute the function: that will do everything as I prefer it; but I would like to leave the second script as is to be executable from shell by itself, as it is now.)
Does anybody have an idea how to do my whim?