Skip to content

Commit

Permalink
Merge pull request #36977 from twangboy/fix_cmd_run
Browse files Browse the repository at this point in the history
Remove whitespace from string commands
  • Loading branch information
Erik Johnson committed Oct 17, 2016
2 parents 9378b22 + 6586050 commit f8cd7b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions salt/modules/cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ def _run(cmd,
raise CommandExecutionError('VT not available on windows')

if shell.lower().strip() == 'powershell':
# Strip whitespace
if isinstance(cmd, six.string_types):
cmd = cmd.strip()

# If we were called by script(), then fakeout the Windows
# shell to run a Powershell script.
# Else just run a Powershell command.
Expand All @@ -289,9 +293,9 @@ def _run(cmd,
# The last item in the list [-1] is the current method.
# The third item[2] in each tuple is the name of that method.
if stack[-2][2] == 'script':
cmd = 'Powershell -NonInteractive -ExecutionPolicy Bypass -File ' + cmd
cmd = 'Powershell -NonInteractive -NoProfile -ExecutionPolicy Bypass -File ' + cmd
else:
cmd = 'Powershell -NonInteractive "{0}"'.format(cmd.replace('"', '\\"'))
cmd = 'Powershell -NonInteractive -NoProfile "{0}"'.format(cmd.replace('"', '\\"'))

# munge the cmd and cwd through the template
(cmd, cwd) = _render_cmd(cmd, cwd, template, saltenv, pillarenv, pillar_override)
Expand Down

0 comments on commit f8cd7b7

Please sign in to comment.