[vox-tech] writing to a shell instance
Bruce Wolk
bawolk at ucdavis.edu
Wed Oct 26 16:20:59 PDT 2011
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
More information about the vox-tech
mailing list