Skip to content

Commit bd8efbc

Browse files
committed
Prevent Windows from opening command prompt (matplotlib#4021)
This tells Windows not to create a new window when using Subprocess to save an animation.
1 parent 61fd742 commit bd8efbc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/matplotlib/animation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
from matplotlib import verbose
3232
from matplotlib import rcParams
3333

34+
# Process creation flag for subprocess to prevent it raising a terminal
35+
# window. See for example:
36+
# https://stackoverflow.com/questions/24130623/using-python-subprocess-popen-cant-prevent-exe-stopped-working-prompt
37+
CREATE_NO_WINDOW = 0x08000000
38+
3439
# Other potential writing methods:
3540
# * http://pymedia.org/
3641
# * libmng (produces swf) python wrappers: https://github.com/libming/libming
@@ -189,7 +194,8 @@ def _run(self):
189194
' '.join(command))
190195
self._proc = subprocess.Popen(command, shell=False,
191196
stdout=output, stderr=output,
192-
stdin=subprocess.PIPE)
197+
stdin=subprocess.PIPE,
198+
creationflags=CREATE_NO_WINDOW)
193199

194200
def finish(self):
195201
'Finish any processing for writing the movie.'
@@ -251,7 +257,8 @@ def isAvailable(cls):
251257
p = subprocess.Popen(cls.bin_path(),
252258
shell=False,
253259
stdout=subprocess.PIPE,
254-
stderr=subprocess.PIPE)
260+
stderr=subprocess.PIPE,
261+
creationflags=CREATE_NO_WINDOW)
255262
p.communicate()
256263
return True
257264
except OSError:

0 commit comments

Comments
 (0)