Skip to content

Commit

Permalink
Allow for using either subprocess.Popen() or subprocess.run()
Browse files Browse the repository at this point in the history
  • Loading branch information
homebysix committed Nov 1, 2020
1 parent 600a900 commit 6d122f3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions scripts/recipe_robot_lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import plistlib
import re
import shlex
import subprocess
import sys
import timeit
from datetime import datetime
from functools import wraps
from random import choice as random_choice
from subprocess import PIPE, Popen
from urllib.parse import quote_plus

# pylint: disable=no-name-in-module
Expand Down Expand Up @@ -335,11 +335,23 @@ def get_exitcode_stdout_stderr(cmd, stdin="", text=True):
robo_print("Shell command: %s" % cmd, LogLevel.DEBUG, 4)
try:
# First try to return text output.
proc = Popen(shlex.split(cmd), stdin=PIPE, stdout=PIPE, stderr=PIPE, text=text)
proc = subprocess.Popen(
shlex.split(cmd),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=text,
)
out, err = proc.communicate(stdin)
except UnicodeDecodeError:
# If that fails, force bytes output.
proc = Popen(shlex.split(cmd), stdin=PIPE, stdout=PIPE, stderr=PIPE, text=False)
proc = subprocess.Popen(
shlex.split(cmd),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=False,
)
out, err = proc.communicate(stdin)
exitcode = proc.returncode

Expand Down

0 comments on commit 6d122f3

Please sign in to comment.