[comp.lang.perl] read/write pipe

marc@athena.mit.edu (Marc Horowitz) (02/24/91)

I know this has been mentioned here before, but I don't remember what
the reasons were.  Why is open(FOO,"|cat|") (a pipe to a program which
I can read from and write to) not supported?  If a patch were to land
in your mailbox, Larry, would you consider taking it?  If so, I might
consider writing it.

The reason I want this is because I have a remote database server, and
a client which accepts "operation arg1 arg2 ..." as input, and gives
whitespace separated fields as a response.  I'd like to open a pipe to
this process so I can write queries and read back responses.  For now,
I can use pipe, fork, and exec, but having this functionality in open
is a lot more elegant, even if it isn't necessarily portable (like to
MS-DOS).

		Marc

tchrist@convex.COM (Tom Christiansen) (02/25/91)

I think that making "|foo|" be a two-way pipe would be giving the novice
enough rope to hang himself.  He would not understand why his programs
didn't work.  By the time he understands files enough to know why this
simplistic approach is so perilous, if he still wants one, he can either
cobble together his own version or pull out &open2() from the FAQ.

--tom
-- 
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn

 Tom Christiansen                tchrist@convex.com      convex!tchrist

ea08+@andrew.cmu.edu (Eric A. Anderson) (02/28/91)

marc@athena.mit.edu (Marc Horowitz) writes:
> |> From the keyboard of marc@mit.edu:
> |> :I know this has been mentioned here before, but I don't remember what
> |> :the reasons were.  Why is open(FOO,"|cat|") (a pipe to a program which
> |> :I can read from and write to) not supported?  
> |> 
> |> From the FAQ:
> |> 
> |>     20) How do I open a pipe both to and from a command?
> |> 
> |>      In general, this is a dangerous move because you can find yourself in
> |>      deadlock situation.  It's better to put one end of the pipe to a file.
For whatever reason, I found that open(FOO,'ftp |'); allowed me to do
both writes and reads from FOO.  Is this a mis-feature or something?
Because I find this fundamentaly useful, I want a program which can do
things with ftp sessions.  (Primarily, get all files under some
directory subject to certain constraints.)  The only other way to do
this would be to write a C program containing all of ftp which seems
like overkill.  Am I in risk of a deadlock or something?
          -Eric
*********************************************************
"My life is full of additional complications spinning around until
 it makes my head snap off."
           -Unc. Known.
"You are very smart, shut up."
           -In "The Princess Bride"
*********************************************************

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/02/91)

In article <Mbn9n5G00VQoA9qdhX@andrew.cmu.edu> ea08+@andrew.cmu.edu (Eric A. Anderson) writes:
: For whatever reason, I found that open(FOO,'ftp |'); allowed me to do
: both writes and reads from FOO.  Is this a mis-feature or something?

Uh, you might well be able to write to the input pipe if it's implemented
as a socket or stream, but the real question is why ftp would be reading
its stdout.  Are you actually able to interact with ftp this way?  Weird.
ftp's stdin should be hooked up to whatever stdin your perl script is using.

: Because I find this fundamentaly useful, I want a program which can do
: things with ftp sessions.  (Primarily, get all files under some
: directory subject to certain constraints.)  The only other way to do
: this would be to write a C program containing all of ftp which seems
: like overkill.  Am I in risk of a deadlock or something?

Not likely with ftp, as long as you stay in sync and read everything there
is to read before going on to the next command.

Larry

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (03/02/91)

As quoted from <1991Feb23.205035.21729@convex.com> by tchrist@convex.COM (Tom Christiansen):
+---------------
| From the keyboard of marc@mit.edu:
| :I know this has been mentioned here before, but I don't remember what
| :the reasons were.  Why is open(FOO,"|cat|") (a pipe to a program which
| :I can read from and write to) not supported?  
| 
| From the FAQ:
| 
|     20) How do I open a pipe both to and from a command?
| 
| 	In general, this is a dangerous move because you can find yourself in
| 	deadlock situation.  It's better to put one end of the pipe to a file.
+---------------

True, but there is a class of programs designed to work this way (like some
database servers, as marc@mit mentioned).

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY