Python: Execute a command in a subshell without cmd interface or hidden or in background
I would like to know how I could execute a command whitout appears the cmd window. My code is in Python and the O.S. is Windows7.
The problematic line is:
os.system(pathandarguments)
The program works fine, execute the given path with the arguments but I loose the control of my program because my program window minimizes, I see cmd window a seconds and then my window program dont maximizes.
I want to execute the string pathandarguments without minimize my principal window. I prefer, if its possible, dont show cmd window. I tried differents ways to make this:
os.system(pathandarguments)
= works fine but minimizes my program window.
os.popen(pathandarguments)
= ERROR: CThread::staticThread : Access violation at 0x77498c19: Writing l开发者_开发技巧ocation 0x00000014
(Don't work)
subprocess.Popen([pathandarguments], shell=False)
= Exception in python script's onAction (Don't work)
Thanks in advance.
EDIT @martineau, The problem is not that I cannot import process, revising the log of my app I saw the problem is with import process at line 146:
13:42:20 T:4116 M:2156859392 NOTICE: import win32api
13:42:20 T:4116 M:2156859392 NOTICE: ImportError
13:42:20 T:4116 M:2156859392 NOTICE: :
13:42:20 T:4116 M:2156859392 NOTICE: No module named win32api
I dont have module win32api.
For a long time I've been using an open source Python module for process control called process-python. The Project Status there says "In its current state it was used heavily in the commercial Komodo IDE project." It's multiplatform, but one of the main reasons I started using it was because on Windows it will spawn a process without a console window. It's very simple to use. Here's a trivial example:
import process
p = process.ProcessOpen([eventfilepath]) # open text file with associated program
ignored_exitstatus = p.wait()
Hope this helps.
精彩评论