On Fri, 27 Feb 2009, John Summerfield wrote:

> >
> > will establish a TCP connection to ${PORT} on ${HOST}. Replace
> > /dev/tcp/... with /dev/udp/... and it will do udp instead of tcp. This
> > redirects stdout. Of course, using < instead of > will redirect stdin and
> > do a read. So, if you like "netcat" to send some data ala
> >
> > command | nc ${HOST} ${PORT}
> >
> > you can use the above > redirection instead and
> >
> > command </dev/tcp/${HOST}/${PORT}
> >
> > instead of
> >
> > nc -l ${HOST} ${PORT} | command
> >
> > NBD - but it saves forking a process.
> but how does one carry on a sensible conversation? I can send stuff to
> sendmail, but how do I get its responses?

You can't. It is like netcat - communications is unidirectional. I guess
if the far end sends something back over the socket, it is quietly
dropped. Netcat has the same problem. It either sends or receives, but not
both. What you'd like would be more like a bidirectional pipe, if there
were such a thing. IIRC, "pipes" in UNIX are unidirectional. So
bidirectional communications requires two pipes. Something like that might
be possible using this, but I can't really think of how. That might be a
nice enhancement both for IP communications and "piped" communications.
Perhaps a <> symbol?

cmd1 <> cmd2

could possible "cross connect" stdout of cmd1 to stdin of cmd2 as well as
stdin of cmd1 to stdout of cmd2, allowing bidirectional communications.
Use of different fd number could be possible with:

cmd1 n<>m cmd2

where n and m are numbers so that /dev/fd/n of cmd1 talks to /dev/fd/m of
cmd2 and /dev/fd/m of cmd1 to /dev/fd/n of cmd2.

The above would be complicated if somebody naively did:

cmd1 | cmd2 <> cmd3 | cmd4

In any case, unidirectionality does decrease its utility somewhat.  But I
doubt that any of us would say that piping output from one command to
another is useless because the second command cannot send anything back to
the first command. How do you get responses back from sendmail if you pipe
to it?

--
Q: What do theoretical physicists drink beer from?
A: Ein Stein.

Maranatha!
John McKown

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to