Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Question about two-sided connections to perl Keywords: popen pseudo-ttys process-connection Message-ID: <6818@jpl-devvax.JPL.NASA.GOV> Date: 17 Jan 90 19:46:25 GMT References: <3196@taux01.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 53 In article <3196@taux01.UUCP> arielf@taux01.UUCP (Ariel Faigon) writes: : --- Question no. 1: : Is there a simple way to connect a perl program to both sides of a process ? : i.e. I would love to be able to do something like: : : open(OUTPTY,"| some_program |",INPTY) ...; : : pipe input into 'some_program' : and read its output in order to post-process it. No. The only ways to do that currently involve using either sockets, fifos, or ptys. And the above syntax, if implemented, wouldn't use a pty anyway. It would probably use a socket pair, and you'd be responsible to use select to avoid deadlock. : Of course, suppose 'some_program' is "interactive" in nature and the : 'pipes' are actually pseudo-ttys (otherwise, a deadlock between perl : & 'some_program' is likely to occur). So I assume I can write to : 'some_program' and read its immediate "reply" alternately. A big assumption. What if it takes 2 seconds? : This brings me to: : : --- Question no. 2: : Can I make 'some_program' that is connected to Perl, think it is writing into : a pty instead of a pipe (actually what I need is that 'some_program' _output_ : be unbuffered - note, I'm not asking about unbuffering perl-output which : is simple). Perl can't make some other program do unbuffered (or line-buffered) output without the cooperation of that process. For most processes, the only way to finagle that is by running them under a pty. : I'm afraid I'll need to write all the 'pty' stuff myself which I : can do in 'C' in the first place. But if you write the pty stuff in perl and send it out, you'll be eternally beloved. I'd do it if I had the time. What do you need besides open and ioctl? And mayby fcntl to set FNDELAY? Of course, you still have to make sure your protocol is correct. How do you know when you've read everything the other program has to say? How do you keep from getting out of sync? If you had a reliable way of determining all the processes that were running on the other end, I suppose you could just wait till they were all blocked, and then return whatever output you'd collected. Larry