Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: running script within a script (semi-interactive)

by tospo (Hermit)
on Oct 05, 2010 at 07:04 UTC ( [id://863523]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://863523]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found