brijeshsnm has asked for the wisdom of the Perl Monks concerning the following question:

I want to read and write to a process (like tripwire) after polling its o/p, I am working on windows platform, Currently am trying open3 for that but the problem is that the message which Iam sending through "Print $wtr message", to my process is getting lost. here is the code,where I am passing valid date to date command after two invalid one but valid date is not getting accepted third time.
use IPC::Open3; use Symbol; use FileHandle; open ABC,">output.txt"; open DEF,">Eoutput.txt"; $WTR = gensym(); # get a reference to a typeglob $RDR = ">&ABC"; # and another one $ERRR = ">&DEF"; # and another one $pid = open3($WTR, $RDR, $ERRR,'date'); STDIN->autoflush(); STDOUT->autoflush(); ABC->autoflush(); $WTR->autoflush(); print $WTR "3//3//3 \n"; print $WTR "4//4/3 \n"; print $WTR "4/5/3 \n"; waitpid $pid,0;
the o/p which iam getting is
The current date is: Sat 04/05/2003 Enter the new date: (mm-dd-yy) 3//3//34//4/34/5/3 The system cannot accept the date entered. Enter the new date: (mm-dd-yy)
all the three messages r getting concatenated then passed. but If i use "\n" in first print to process statement then i get
The current date is: Sat 04/05/2003 Enter the new date: (mm-dd-yy) 3//3//3 The system cannot accept the date entered. Enter the new date: (mm-dd-yy)
the next two messages are getting lost, the o/p which iam expecting is
The current date is: Sat 04/05/2003 Enter the new date: (mm-dd-yy) 3//3//3 The system cannot accept the date entered. Enter the new date: (mm-dd-yy) 4//4/3 The system cannot accept the date entered. Enter the new date: (mm-dd-yy) 4/5/3

Replies are listed 'Best First'.
Re: open3, process sychronization problem
by kvale (Monsignor) on Feb 02, 2004 at 10:48 UTC
    I don't know the details of communication with Tripwire, but have a general comment.

    The problem you are having may be due to the fact that you are not waiting for Tripwire to come back with a command prompt before printing another date. Input gets all bunched up.

    I suggest that you use an approach like

    1. open the connection 2. print the date 3. read in response until a prompt for a new date 4. goto 2 until done
    Most bidirectional communication is like this, an alternating write and read.

    -Mark

      thanks mark, another problem is that, I read from process and write to it only after polling its o/p, but sometime the process doesnt flush its o/p in my $read variable ( if its not stdout) , causing my program to loop infinitly, is there any library like comm.pl or ptty in window which could solve my problem?