Executing python script without writing to the screen

butterhook used Ask the Experts™

I'm running ActivePython 2.5 (or 2.6) on Windows Server 2003.

When a script runs i.e. blahblah.py is called from the command line, even if the script does not output anything to the display, a black command line style box pops up.

Is it possible to adjust the script, or indeed the way it is called, so that it doesn't pop this box up - so it just runs in the background? There isn't really anything that the user needs to see, as the script is run by a scheduled task.

Maybe the answer is to write to a file?

Help would be much appreciated :)

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
HonorGodSoftware Engineer

How do you "call the script from the command line"?

If I use:

python scriptName.py parameters

it doesn't open a new command prompt.

So, how is it you are calling this script, and what does it do?

For example, the following only
import os, re;

def main() :

if ( __name__ == '__main__' ) :
else :
  print 'Usage: python myScript.py';

Open in new window

HonorGodSoftware Engineer

hm... Sorry about that.  I meant to attach the following image:

The following only display's stuff to the screen if myScript is imported, instead of executed.
HonorGodSoftware Engineer

Command prompt execution of myScript.py

If your python script does not output anything to stdout, then just rename it from
into script.pyw

This should work.

What happens is rather simple.

Windows has a file association to start a file ending with.py with
python.exe (with console)

and any script ending with .pyw with
pythonw.exe (windows application without console)

so either rename it to .pyw
or call it explicitely



Hi - that last answer looks exactly like what I need... will check out... Thanks


Brilliant work!
The gelonida's suggestion is definitely the correct one.  For calling it from the script, I would prefer the explicit call to pythonw.exe (just replace the call to python.exe by pythonw.exe).

The 'w' stands for "windowing application".  This was created namely for executing Python application that are not "console applications", i.e. for the applications that create the GUI windows.  The extra console window would otherwise look strange (say the application using the wxPython, PyQT, Tcl/Tk, or the like).

It is perfectly clean that the process runs silently (no visible output).  You only should add a kind of simple logging the activity to help to discover the problems when the things go wrong.


Thanks pepr - yes, I agree that in this context that some sort of file log or audit will be essential if there is no output to the screen.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial