4

I'm new to subprocess.Popen and have been reading the docs. I'm just trying to make my process not open a console. Which of these parameters do I need?

stdout=subprocess.PIPE,
shell=False,
creationflags = CREATE_NO_WINDOW

Will this only work for Windows? Do I need to do something different for it to work on Mac?

Thanks!

Kijewski
  • 25,517
  • 12
  • 101
  • 143
User
  • 23,729
  • 38
  • 124
  • 207
  • 1
    I'm pretty sure that on POSIX platforms (like a Mac) you're not going to actually see a console under any circumstances. – dano Aug 04 '14 at 16:22
  • possible duplicate of [Cross-platform subprocess with hidden window](http://stackoverflow.com/questions/1016384/cross-platform-subprocess-with-hidden-window) – dano Aug 04 '14 at 16:24
  • It doesn't talk about my parameters in that question, just some other `startupinfo`. Would appreciate someone shedding some light. – User Aug 04 '14 at 16:54
  • I added an answer that directly addresses all the arguments you listed. – dano Aug 04 '14 at 17:10

1 Answers1

13

stdout=subprocess.PIPE has no effect on whether or not a console appears. It just determines whether or not the stdout of the subprocess is captured in a pipe that you can read from or not.

shell=False is the default for all subprocess commands, so you don't need to provide it. It tells subprocess whether or not to use a shell to execute the provided command. It does not have any effect on whether or not a console appears on any platform.

creationflags = CREATE_NO_WINDOW will indeed hide the console on Windows (tested on Windows 7, assuming CREATE_NO_WINDOW == 0x08000000). It will cause an error to use it on non-Windows platforms, though. You should reference this question for a way to only provide creationflags on Windows, and also for alternative way to hide the console.

Note that the console appearing should only be an issue on Windows. On Posix platforms the console shouldn't ever appear when running subprocesses.

Community
  • 1
  • 1
dano
  • 91,354
  • 19
  • 222
  • 219