Link to home
Start Free TrialLog in
Avatar of butterhook
butterhookFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Executing python script without writing to the screen

Hello

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 :)

Avatar of HonorGod
HonorGod
Flag of United States of America image

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() :
  pass;

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

Open in new window

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.
Command prompt execution of myScript.py
myScript.jpg
ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of butterhook

ASKER

Hi - that last answer looks exactly like what I need... will check out... Thanks
Brilliant work!
Avatar of pepr
pepr

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.