Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:22:50+00:00 2026-06-06T16:22:50+00:00

I am trying to make a Master perl script calling children perl script and

  • 0

I am trying to make a Master perl script calling children perl script and interacting through a pipe.

I have write this code for the master :

#!/usr/bin/env perl

use strict;
use warnings;

use IPC::Open3;

my @children;

for my $i ( 0 .. 4 ) {
    print "Master: " . $i . ", I summon you\n";

    $children[$i] = {};

    $children[$i]->{'pid'} = open3( my $CH_IN, my $CH_OUT, my $CH_ERR, 'perl child.pl -i ' . $i );

    $children[$i]->{'_STDIN'}  = $CH_IN;
    $children[$i]->{'_STDOUT'} = $CH_OUT;
    $children[$i]->{'_STDERR'} = $CH_ERR;

    my $line = readline $children[$i]->{'_STDOUT'};
    print $line ;

}

print "Master: Go fetch me the sacred crown\n";

for my $i ( 0 .. 4 ) {
    $children[$i]->{'_STDIN'}->write("fetch the sacred crown\n");
    my $line = readline $children[$i]->{'_STDIN'};
    print $line ;
}

print "Master: Thanks. Now die!!!\n";

for my $i ( 0 .. 4 ) {
    $children[$i]->{'_STDIN'}->write("die !!\n");
    my $line = readline $children[$i]->{'_STDIN'};
    print $line ;
}

And this one for the child :

#!/usr/bin/env perl

use Getopt::Long ;

my $cmdline_id ;

GetOptions ('i=s' => \$cmdline_id) ;

my $id = $cmdline_id ;

exit 1 if !defined $id ;

print "I am $id, and I am awaken\n" ;

while(<STDIN>) {
    print STDOUT $id . ': Master ask me to ' . $_ ;

    if ($_ =~ /exit/oi) {
        exit 0 ;
    }
}

But when I launch the Master he just hung while reading the response from the child.

Any idea about what I did wrong, and why ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:22:52+00:00Added an answer on June 6, 2026 at 4:22 pm

    You are suffering from buffering.

    Say $|=1 near the beginning of the child process to allow the child to print without waiting for the output buffer to fill up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
So I'm a little new at this, a the code I have so far
I'm trying to add a script reference to jQuery in my master page so
Hopefully I can explain this to where it make sense, but I'm trying to
i'm new with RoR and i'm trying to make a master-datail: User -Lugar(place) My
I'm trying to make use of the extended HTML Helper DisplayFor in this View:
I'm trying to make an AJAXy submission and have the resulting partial be inserted
I'm trying to learn how to make databases, using C# as the master language.
i'm trying to make my site master page ( views/shared/site.master ) strongly typed. eg.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.