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 18:46

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

On 10/26/2011 03:34 PM, Norm Matloff wrote:
> Here's what I'd like to do.  I'm running code, in this case Python, in
> xterm A (replace by your favorite terminal emulator), and want that code
> to write to xterm B, just as if I had typed directly into xterm B.
> Say for example I want to run the ls command in xterm B, but do so via
> some action in A.  Say the latter is /dev/pts/8.  I could run the Python
> code
> import os
> os.system('echo "ls">  /dev/pts/8')
> I have 2 questions:
> 1.  How do I get the end-of-line character in there, so that the ls
> command actually runs?  I've tried "ls\n", "ls \r\n" and lots of
> variants, e.g.
> echocmd = 'echo "ls'+chr(14)+chr(10)+'">  /dev/pts/13'
> os.system(echocmd)
> But no matter what I try, it doesn't work.  The "ls" does appear in
> xterm B, and the newlines, but it's still expecting more input from me.
> If I manually hit Enter in xterm B, then it works.
> I know this must be simple ridiculously simple, but I don't see it.
> Yes, I know I could use a pipe here, but I want to retain the ability to
> manually type in xterm B, i.e. I want to be able to input there either
> by physically typing there or by having the program in xterm B do it.
> Maybe I can launch xterm A via a pipe in the first place?  I've tried
> that a bit, but don't have enough experience with pipes to see how to
> make that work either.
> One solution is to use "screen," which is what I'm doing currently,
> but some people would like to use my program from Windows.
> 2.  Which brings me to my next question:  How can I do this in Windows?
> (Not Cygwin.)
> Any ideas would be much appreciated.
> Norm

As for question 1, backticks are what you want:

echo `ls` > /dev/pts/8
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:
Sunset Systems
Who graciously hosts our website & mailing lists!