Jump to content
Sign in to follow this  

Console windows and processes

Recommended Posts

Working in Python.

If I have:

auto_it = win32com.client.Dispatch("AutoItX3.Control")
cmd = "python test.py"

and then I use:

pid = auto_it.Run('%s /c start %s' % (os.getenv('COMSPEC'), cmd))

I get a new console window with python.exe running test.py.

The problem is that the pid points to a non-existant process. I'm assuming this has something to do with calling python.exe via the DOS start command.

So, my next step is to try this:

>>> print auto_it.Run('%s /c %s' % (os.getenv('COMSPEC'), cmd))

Now the big problem is that it takes over the current console window...thus the reason I have to use the print statement to see the PID. I can open another console window and use tasklist.exe to see that 6156 is indeed python.exe.

The same issue presents itself if I just use:

print auto_it.Run(cmd)

So, in summary...how can I get a new console window to open with auto_it.Run() while at the same time getting a valid PID for that process?

Share this post

Link to post
Share on other sites

Why use AutoIt.Run when you can use Python's native os & system modules to run external processes? Did you need AutoIt for something beyond the Run method as well?

If it's just to get PIDs, Python may have support for that in the os & system modules, and you could also use SysInternals ps tools like PsExec.exe to do the same thing.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...