Merge pull request #34201 from DarkKnightCZ/cmdmod-34199

Suffix temp file with .sr1 and add mandatory argument when executing PowerShell script
This commit is contained in:
Mike Place 2016-06-22 10:21:24 -07:00 committed by GitHub
commit 606ae3c886

View file

@ -2271,10 +2271,21 @@ def exec_code_all(lang, code, cwd=None):
salt '*' cmd.exec_code_all ruby 'puts "cheese"'
'''
codefile = salt.utils.mkstemp()
powershell = lang.lower().startswith("powershell")
if powershell:
codefile = salt.utils.mkstemp(suffix=".ps1")
else:
codefile = salt.utils.mkstemp()
with salt.utils.fopen(codefile, 'w+t', binary=False) as fp_:
fp_.write(code)
cmd = [lang, codefile]
if powershell:
cmd = [lang, "-File", codefile]
else:
cmd = [lang, codefile]
ret = run_all(cmd, cwd=cwd, python_shell=False)
os.remove(codefile)
return ret