automate commands to an .exe console program through python

Juan Perez corleone82 at gmail.com
Wed Dec 14 07:31:21 EST 2011


Hi,

Well if I can remmeber since last time I did something similar in C, it was
close stdin channel in the open devices table (I don't know if it is the
correct name in english, I learnt it in spanish) and put a pipe on it and
then create a fork, parent it comunicates to the child through the pipe, so
if child run a shell program, through exec, you should be able to
comunicate to his stdin through his parent... I think that was correct, if
I remmember well...

My app is console app, working by basic commands like send cd or dir to the
console. I thought redirecting stdin (keypad) I could send this basic
comands to it... but obviously I was completely wrong...

I can not use dedicated virtual machines, and it has to be as similar as
user environment as possible, and it can appear new windows that takes
focus, so I have to assure i can get the focus every time before sending
commands.... Quite tricky stuff.... if it is possible to do something like
that in Python I can struggle a bit more, if not better leave right now
before wasting time with nonsenses...
Thanks,
Juan

2011/12/13 Chris Angelico <rosuav at gmail.com>

> On Tue, Dec 13, 2011 at 11:35 PM, Juan Perez <corleone82 at gmail.com> wrote:
> > 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.
>
> It is (at least, it supports the basics of pipes and redirection); but
> what you're looking at here is an application that appears not to use
> STDIN.
>
> > 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?
>
> You may be able to put focus to the window before sending it keys, but
> this is sounding extremely hackish (nearly as bad as the Magic: The
> Gathering Online trade-bot system). I'm thinking here the best option
> may be to give this a dedicated virtual machine and let it do whatever
> it likes - effectively, have an entire "computer" dedicated to just
> this application and its automation harness. That would probably make
> things simple enough that you don't need to worry too much about
> focus, sending keystrokes to other windows, etc.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111214/6a58b2b3/attachment-0001.html>


More information about the Python-list mailing list