[vox-tech] writing to a shell instance

Harold Lee harold at hotelling.net
Wed Oct 26 17:27:02 PDT 2011


You could do this at an X11 level, e.g.

http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html

This tool looks promising also, but I haven't tried it:

http://www.semicomplete.com/projects/xdotool/

I think you'd need to use some Windows API to do this there.

Harold

On Wed, Oct 26, 2011 at 4:20 PM, Bruce Wolk <bawolk at ucdavis.edu> wrote:
> 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
> vox-tech at lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech
>


More information about the vox-tech mailing list