0

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.

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.

aefxx
  • 24,835
  • 6
  • 45
  • 55
GerarLM
  • 1
  • 1
  • 1
  • The shell=False is probably the nearest but what do you mean by the python scrip's onAction? – mmmmmm Sep 16 '10 at 17:21
  • I tried too: subprocess.Popen([sacarThumb], shell=True) = The program don't do anything. My python script have a button and, when I click button, execute the code of the function that has the line os.system(pathandarguments) or os.system(pathandarguments) or subprocess.Popen([pathandarguments], shell=False) ... – GerarLM Sep 16 '10 at 17:29
  • @Sam888: The OP says nothing about trying to execute a Python script without a cmd window appearing...which is what the link you provided is all about. – martineau May 28 '12 at 15:55

1 Answers1

1

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
  • 119,623
  • 25
  • 170
  • 301