Suffix temp file with .sr1 and add -File argument when executing PowerShell code via cmdmod.exec_code

Fixes #34199
This commit is contained in:
Lukas Raska 2016-06-22 13:00:49 +02:00
parent 04553cd3de
commit 05748743bc

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