NSPipe or NSFileHandle buffering?
NSPipe or NSFileHandle buffering?
- Subject: NSPipe or NSFileHandle buffering?
- From: mw <email@hidden>
- Date: Sun, 01 Dec 2002 11:09:00 -0500
Hello,
I wrote a Perl backend for a program I plan on writing. I just finished
writing a (very, very simple) frontend to the program to make sure it works
okay with Cocoa over pipes. The Perl program first takes 6 values via STDIN
(they are all in a row).
chomp($pop3host = <STDIN>);
chomp($filter_type = <STDIN>);
chomp($filter_match = <STDIN>);
chomp($username = <STDIN>);
chomp($password = <STDIN>);
chomp($delete = <STDIN>);
So I figured that in my Cocoa program, I should be able to have 6 method
calls in a row to write all of this information to the Perl program (entered
in text fields).
[writeHandle writeData: [NSData dataWithBytes:[popServer cString]
length:[popServer cStringLength]]];
[writeHandle writeData: [NSData dataWithBytes:[filterField cString]
length:[filterField cStringLength]]];
[writeHandle writeData: [NSData dataWithBytes:[filterFieldValue cString]
length:[filterFieldValue cStringLength]]];
[writeHandle writeData: [NSData dataWithBytes:[username cString]
length:[username cStringLength]]];
[writeHandle writeData: [NSData dataWithBytes:[password cString]
length:[password cStringLength]]];
[writeHandle writeData: [NSData dataWithBytes:[delete cString]
length:[delete cStringLength]]];
[writeHandle closeFile];
The NSTask and everything else is working okay, so no debugging there is
needed :-).
Now, in the Perl program, it kept not connecting to the POP3 server and I
was baffled. So I put some debugging code in there to simply print out all
of the values that were inputted by the first chunk of code I presented, and
I had \n after each of the values to make it readable. But for some reason,
they were all printed back to the Cocoa program in one line. This baffled me
even further, so I removed all of the debugging code in the Perl program
except for the first line (which was supposed to print back the name of the
POP3 server that was entered). This printed back ALL OF THE VALUES THAT HAD
BEEN SENT OVER. That answered a lot of questions.
So it seems that when I am writing information from the Cocoa program to the
Perl program, it buffers everything somewhere between the two programs in
the "pipes", and then writes everything to a single variable, leaving all of
the other Perl variables undefined or empty.
I tried using this code in the perl program to turn off buffering for STDIN:
select STDIN;
$|=1;
as recommended by several websites, but that does nothing since I am not
technically inputting data from the terminal.
Does anybody have any idea what is going on here, and how to turn it off (if
it really is buffering like I think)??? I have looked everywhere and there
is nothing on this. I have no idea whether the information is being buffered
on the Cocoa end or on the Perl end either.
TIA,
mw
P.S. The Perl program works fine on the command line, so there isn't
anything buggy about the Perl code. Just a heads-up :-).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.