automate commands to an .exe console program through python

Juan Perez corleone82 at gmail.com
Tue Dec 13 07:35:28 EST 2011


Thank you for your responses,

My problem is thinking in windows console somewhat like linux shell, and do
same things I did with pipes in C programming. But it seems not to be the
case.
At a glance I dare say that sendkeys module is useful  enough, but if I've
understood well, you only can send messages to focused window, that will
report some inestabilities if windows focused is changed. You won't be able
to touch anything in the current laptop. So, is there any way to identify
the a process/window and send keystrokes in a smarter way and/or is it
possible to identify a window an get the focus on it?

I'm worried that pexpect is a too dificult way...

Thanks,

Juan

2011/12/13 Tim Golden <mail at timgolden.me.uk>

> On 13/12/2011 11:21, Juan Perez wrote:
>
>> Well, if developers have to change something to the code, I'd continue
>> with autoit, since is closer to real enviroment. You are right, autoit
>> work by send parametres to GUI focused, but really I don't think it's
>> something necessary for my purposes as I need only send parameters to a
>> windows cmd console. Do you know if is that possible by piping standard
>> input? I've tried but with no results. What I'd need is open a new
>> windows console get the pid and send messages to it through stdin pipe.
>> But I've been unable to do it so far.
>>
>
> I think that you're thinking about this the wrong way. You're talking
> about automating a Console program as though it were notepad: by sending
> keystrokes. Mixed in with that you've got some kind of notion of piping
> stdin/stdout.
>
> If you've got a (non-GUI) program which you usually run in a Console
> context, it will either take its input from stdin -- in which case,
> ignore the fact it runs in a console and feed it via subprocess --
> or it will take input from some kind of Console-level getch method,
> in which case you'll have to use something like SendKeys [1] or perhaps
> WinPexpect [2]
>
> Don't know if that helps at all...
>
> TJG
>
>
> [1] http://www.rutherfurd.net/**python/sendkeys/<http://www.rutherfurd.net/python/sendkeys/>
>
> [2] https://bitbucket.org/geertj/**winpexpect/wiki/Home<https://bitbucket.org/geertj/winpexpect/wiki/Home>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111213/6a9440e1/attachment-0001.html>


More information about the Python-list mailing list