perl help with pipes and file handles (simple issue)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl help with pipes and file handles (simple issue)
# 1  
Old 05-06-2007
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 Smilie

can someone please help me out here ? Smilie Smilie

Thanks !
# 2  
Old 05-06-2007
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";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

2. UNIX for Dummies Questions & Answers

Script to leak file handles

This is a strange one. We have an issue where our system is leaking SCTP file handles. There are people working on this and in the mean time we have a monitoring script that alarms when we need to perform actions to manually clear them. For testing purposes I want to write a script that... (0 Replies)
Discussion started by: RECrerar
0 Replies

3. Shell Programming and Scripting

Simple Question about Reading file by Perl

Hi , I just write a simple function to read the file line by line. But when I run it it says out of memory. I am not sure about the root cause, Can someone help me out of this? :D #! /usr/bin/perl use strict; sub checkAPs{ my $NDPDir = "/home/eweiqqu/NCB/NDP_files/"; ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

4. Programming

please help a problem in client-server ipc message 2 pipes communication simple example

I want to have a message send & receive through 2 half-duplex pipes Flow of data top half pipe stdin--->parent(client) fd1--->pipe1-->child(server) fd1 bottom half pipe child(server) fd2---->pipe2--->parent(client) fd2--->stdout I need to have boundary structed message... (1 Reply)
Discussion started by: ouou
1 Replies

5. UNIX for Advanced & Expert Users

sendmails works, but opens 43 file handles per email -> problem

I'm using Sendmail 8.13.8 on a CentOS 5.5 vServer (Virtuozzo). I'm using a loop in PHP to send a lot of HTML-mails via sendmail. Each mail is a mail with individual statistics for our users, so its not mass mailing, bcc is not an option. It all works fine, but when I take a closer look there... (2 Replies)
Discussion started by: ZX81
2 Replies

6. UNIX for Advanced & Expert Users

How UNIX/AIX handles a file deep down, say it's being read while another one tries to rename it?

Hi Thinkers, On AIX 5.3, we have a monitor program that reads the log file and searching for a certain string pattern that we define(say "transactionException"), if it sees it then it will raise an alert by sending an email. Because the log file XXX.log is rolling into XXX.log.0, XXX.log.1,... (2 Replies)
Discussion started by: TheGunMan
2 Replies

7. Shell Programming and Scripting

Monitor open file handles used by a process

We have a process that is running out of file handles. Is there some command line way to determine this that we can include into a cron script? Please let me know JAK (3 Replies)
Discussion started by: jakSun8
3 Replies

8. Shell Programming and Scripting

SSH in batch mode and File-Handles in a loop

Hi all I try to execute SSH commands on several hosts in a while-loop. There seems to be a problem with file-handle, first cycle works correct but no other one will follow due to the while condition is false even that there are many more host entries (lines) in all_hosts.dat. ... (3 Replies)
Discussion started by: DaveCutler
3 Replies

9. UNIX for Advanced & Expert Users

File Handles

Hi, perhaps you can answer my question.....;) How can I check, how many file handles are used and how can i increase the value for maximum file handles??? (3 Replies)
Discussion started by: sjaeger
3 Replies

10. UNIX for Dummies Questions & Answers

Perl, Pipes, and FTP

I am attempting to automate an ftp session in PERL by emulating the user and sending commands to ftp, but I am getting unexpected and unwanted results. Here is a portion code that illustrates the method I am attempting (this was just a shot in the dark): system("( echo open server sleep 1... (2 Replies)
Discussion started by: murdaugh
2 Replies
Login or Register to Ask a Question