Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by andal (Hermit)
on Oct 05, 2010 at 08:35 UTC ( [id://863541]=note: print w/replies, xml ) Need Help??


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

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);

Replies are listed 'Best First'.
Re^3: running script within a script (semi-interactive)
by tospo (Hermit) on Oct 05, 2010 at 08:52 UTC
    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://863541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-18 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found