Ivor,

Thanks for your suggestion. It worked for me, although I had to do the same action in a slightly different way:
while (<STDIN>)
{
if (ord($_) == 26) { last; }
:
:
}

The use of  "&& !/\032/" didn't work for me.

Thanks,
Sam



IvorW wrote:
----- Original Message ----- 
From: "Sampath Ravindhran" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: 07 December 2004 02:40
Subject: How to terminate STDIN to perl through a mailbox ?


  
* Replies will be sent through Spamex to [EMAIL PROTECTED]
* For additional info click -> http://www.spamex.com/i/?v=5111228


I have an application that spawns a detached process to run a Perl 
script, within which it expects to read a bunch of lines from STDIN. To 
do this, I have a simple construct like
-----------
while (<STDIN>)
{
   $myline = $_;
 (process my input line...)
}
------------

Before calling the perl script in the detached process, I define 
sys$input to the mailbox device the parent had created.

When the parent process writes text lines into the mailbox, I find that 
the detached process *does* receive them. After writing the necessary 
lines, I send an EOF  character (decimal 26) to the mailbox expecting it 
to terminate read from STDIN and proceed further with the execution of 
the Perl script. However, that doesn't happen and the Perl execution 
remains in this while loop forever. Closing the channel of the mailbox 
after the write operation is not a desirable option at this point, since 
that  could potentially break other  non-perl related tasks that might 
require to keep the channel open from the parent side. ( I had a similar 
situation earlier where the 'perl' binary was invoked in the detached 
process without any arguments, and the Perl script itself was fed 
through the mailbox as STDIN to the detached process which seemed to 
hang forever too. I got over the hang by sending an EOF character as the 
last message on the mailbox. Looks like the EOF works for the Perl 
script itself on STDIN, but not read of data through STDIN as part of a 
Perl script)

Any suggestions,pointers welcome.
    

Sorry, Ctrl-Z is a terminal driver function. The only way to send EOF is to
close the mailbox. The detached process will see EOF when there are no
writers to the mailbox.

However, you could always modify the perl script to detect Ctrl-Z and process it
as if it were EOF:

$| = 1;
while (<STDIN> && !/\032/ ) {
   ....
}

Hope this helps,

Ivor.
  

Reply via email to