l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2011 Oct 26 19:39

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] writing to a shell instance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] writing to a shell instance

I was wondering if I could get this down to just a few lines of code
then realized that the shell should be able to handle this.  Turns out
it works okay.

In terminal a:
$  while /bin/true; do echo date; sleep 1; done  | nc localhost 9999

In terminal b I run:
( nc -d  -l 9999 & cat) | bash

And I see
Wed Oct 26 19:21:54 PDT 2011
Wed Oct 26 19:21:55 PDT 2011
Wed Oct 26 19:21:56 PDT 2011
Wed Oct 26 19:21:57 PDT 2011

In terminal b if I say ls -al:
Wed Oct 26 19:23:09 PDT 2011
ls -al
total 16
drwxrwsr-x   2 bill bill  4096 2011-10-26 19:18 .
drwxrwsr-x 143 bill bill 12288 2011-10-26 19:18 ..
-rw-rw-r--   1 bill bill     0 2011-10-26 19:18 filea
-rw-rw-r--   1 bill bill     0 2011-10-26 19:18 fileb
Wed Oct 26 19:23:10 PDT 2011

A nice side effect is if I type slowly in terminal B:
Wed Oct 26 19:24:26 PDT 2011
tWed Oct 26 19:24:27 PDT 2011
oWed Oct 26 19:24:28 PDT 2011
uWed Oct 26 19:24:29 PDT 2011
cWed Oct 26 19:24:30 PDT 2011
hWed Oct 26 19:24:31 PDT 2011
 fWed Oct 26 19:24:32 PDT 2011
ilecWed Oct 26 19:24:33 PDT 2011

Wed Oct 26 19:24:34 PDT 2011
filea  fileb  filec
Wed Oct 26 19:24:35 PDT 2011

So basically the buffering means that the streams don't stomp on each
other unnecessarily.  Assuming there's a nc/bash port to windows or a
functional equivalent it should work there as well.

Not pretty, but it seems workable.  You could of course have perl/python
send or receive in either terminal A or B.
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.