Encode shell commands explicitly.

On Windows subprocess.Popen will try to implicity encode shell commands
using the default system encoding. This will raise an exception if
passed utf-8.
This commit is contained in:
Daniel A. Wozniak 2018-08-24 21:21:41 +00:00 committed by rallytime
parent 74b78835b3
commit 238853b9ec
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19
2 changed files with 6 additions and 1 deletions

View file

@ -40,6 +40,8 @@ class TimedProc(object):
if self.timeout and not isinstance(self.timeout, (int, float)):
raise salt.exceptions.TimedProcTimeoutError('Error: timeout {0} must be a number'.format(self.timeout))
if kwargs.get('shell', False):
args = salt.utils.stringutils.to_bytes(args)
try:
self.process = subprocess.Popen(args, **kwargs)

View file

@ -1953,7 +1953,10 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
_expected = 'This is Æ test!'
if salt.utils.platform.is_windows():
# Windows cmd.exe will mangle the output using cmd's codepage.
_expected = "'This is test!'"
if six.PY2:
_expected = "'This is A+ test!'"
else:
_expected = "'This is test!'"
self.assertEqual(_expected, ret[key]['changes']['stdout'])
def tearDown(self):