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
  • 831
  • 5
  • 11
  • 21

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
  • 299,747
  • 42
  • 398
  • 622
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
  • 14,385
  • 12
  • 40
  • 47