tags:

views:

216

answers:

3

Hello all, 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 location 0x00000014 (Don't work)

subprocess.Popen([pathandarguments], shell=False) = Exception in python script's onAction (Don't work)

Thanks in advance.

+1  A: 

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.

martineau
A: 

Thanks but my python code is a plugin for xbmc (http://xbmc.org/) and I suposse there is impossible to install new features. I need a way to spawn a process without a console window opening in Windows7 with original Python (I think is 2.4 version)

GerarLM
@GerarLM, if your 'answer' is a response to mine: You don't need to really install anything to use process-python. It's just a single file named 'process.py' which you can `import` into your script. Also, I haven't actually tried it, but I suspect it would work with PY 2.4 since it's so old.
martineau
Hi, thanks for you time, I noob with python. I copyed process.py into my script folder (in all folders I can because I dont know really well where I have to copy the modules to import, I have resources folder with lib, libs and platform_binaries folders) but, when I run script with the line import process it doesnt work and tell me the Error: "No module named process"
GerarLM
@GerarLM, that's strange. If process.py is in the same folder as your script you should be able to `import process`. You can examine the value of the `sys.path` string to see where Python looking for modules. If the first entry isn't the empty string '', you could try prepending the path the folder it is in to the front of sys.path so it will be found.
martineau
The value of sys.path string is a lot of paths including the same folder as my script, I copyed process.py into my folder script but I cannot be able to import process.
GerarLM
@GerarLM, can you import any other .py module files from the same directory or is it a problem only with process.py? Could it be a filename uppercase/lowercase problem? It bothers me that it says it can't find it (not the there's an error while importing it). You could also try putting it in another folder in your sys.path or making new one for it in say ..\Python\lib\site-packages\Process-Python
martineau
A: 

@martineau, Im GerarLM, the problem is not 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.

@GerarLM. Ahhh, that's a real problem. That is the "Python for Windows extensions". It's very popular and available on SourceForge at <http://sourceforge.net/projects/pywin32/>.
martineau
@GerarLM. Another completely different and unrelated idea would be to make a shortcut to the command you want to execute and set its properties to Run Minimized. That's how I do it for some command shortcuts I keep on my Windows Desktop.
martineau