Skip to content

Commit

Permalink
subprocess; avoid using shell=True during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jul 10, 2022
1 parent a3e569a commit c13017f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import random
import re
import select
import shlex
import shutil
import signal
import socket
Expand Down Expand Up @@ -450,14 +451,14 @@ def sh(cmd, **kwds):
"""run cmd in a subprocess and return its output.
raises RuntimeError on error.
"""
shell = True if isinstance(cmd, (str, unicode)) else False
# Prevents subprocess to open error dialogs in case of error.
flags = 0x8000000 if WINDOWS and shell else 0
kwds.setdefault("shell", shell)
flags = 0x8000000 if WINDOWS else 0
kwds.setdefault("stdout", subprocess.PIPE)
kwds.setdefault("stderr", subprocess.PIPE)
kwds.setdefault("universal_newlines", True)
kwds.setdefault("creationflags", flags)
if isinstance(cmd, str):
cmd = shlex.split(cmd)
p = subprocess.Popen(cmd, **kwds)
_subprocesses_started.add(p)
if PY3:
Expand Down

0 comments on commit c13017f

Please sign in to comment.