1

Possible Duplicate:
How to avoid console window with .pyw file containing os.system call?

Given a piece of Python code like this:

import os
os.system('set')

The CMD window pops up each time, despite me saving the file as a .pyw! Any help appreciated

Community
  • 1
  • 1
user2315
  • 791
  • 5
  • 10
  • 20

2 Answers2

2

It's because you're running Python from a window that you get a pop-up console window. Console programs can only be run from a console, and if the program environment doesn't already include one Windows will helpfully create it.

Mark Ransom
  • 286,393
  • 40
  • 379
  • 604
2

os.system does open a command window by design. The subprocess module should let you do somethings without opening a window.

Also, for certain commands (say copy, delete) you could use specialized OS commands that won't open a command window and have the advantage of being more cross-OS.

TimothyAWiseman
  • 13,397
  • 11
  • 37
  • 47