in reply to running script within a script (semi-interactive)

To capture the output of a script you can use backticks, like this:

my $output = `some_script.pl`;
To pass some_script.pl STDIN, you would open a pipe to it (which is explained in the docs mentioned above).

Replies are listed 'Best First'.
Re^2: running script within a script (semi-interactive)
by andal (Hermit) on Oct 05, 2010 at 08:35 UTC

    This approach won't work. The backticks are blocking the execution and you need to provide the input. So it's a dead-lock. Better to look at perlipc. Though the most generic approach is use of pipes and forks. The "open" command with "-|" or "|-" is very convinient for this. For example

    # this makes the fork and pipes STDOUT of child to OUTPUT of parent. my $pid = open(OUTPUT, "-|"); if($pid == 0) { # we are in child now. To provide input I need another fork. # This time the STDIN of child is piped from INPUT of this process +. my $another_pid = open(INPUT, "| another_script_or_program"); # now check the return value and pass the input thru INPUT print INPUT "my input\n"; exit(0); } # the main process just reads data from OUTPUT print while(<OUTPUT>); # do waitpid close(OUTPUT);
      oh yes, you're right. Definitely a case for pipes.