The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple issue.. the_learner UNIX for Advanced & Expert Users 2 01-17-2008 01:44 PM
SSH in batch mode and File-Handles in a loop DaveCutler Shell Programming and Scripting 3 04-03-2007 03:39 AM
PIPEs and Named PIPEs (FIFO) Buffer size Jus Filesystems, Disks and Memory 1 08-20-2004 07:14 AM
File Handles sjaeger UNIX for Advanced & Expert Users 3 08-10-2001 04:58 AM
Perl, Pipes, and FTP murdaugh UNIX for Dummies Questions & Answers 2 07-03-2001 05:01 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-05-2007
Registered User
 

Join Date: Apr 2007
Posts: 75
perl help with pipes and file handles (simple issue)

Hello,

I have a program which opens a pipe for communication using file handle and forks 5 child processes.

Code:
@waitlist = (1,2,3,4,5);
foreach $item (@waitlist) {
        pipe *{$item},RETHAND;
        unless ($pid = fork()) {
                # Child process
                print RETHAND "Completed $item\n";
                exit(); 
         }
} 

# back to parent...
foreach $item (@waitlist) {
        $response = <$item>;
        print "$response";
}
output is..

Quote:
Completed 1
Completed 2
Completed 3
Completed 4
Completed 5
the only problem is that the child is unable to return multiple lines to the parent..

so in my child process f I have..

Quote:
print RETHAND "Completed $item \n something else here";
The output is still

Quote:
Completed 1
Completed 2
Completed 3
Completed 4
Completed 5
the "something else here" part is ignored

can someone please help me out here ?

Thanks !
Reply With Quote
Forum Sponsor
  #2  
Old 05-06-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,469
What about this?

Code:
@waitlist = (1,2,3,4,5);
foreach $item (@waitlist) {
        pipe *{$item},RETHAND;
        unless ($pid = fork()) {
                # Child process
                print RETHAND "Completed $item\n something else here";
                exit(); 
         }
} 
close(RETHAND);

# back to parent...
foreach $item (@waitlist) {
        @response = <$item>;
        print @response, "\n";
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0