mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Suffix temp file with .sr1 and add -File argument when executing PowerShell code via cmdmod.exec_code
Fixes #34199
This commit is contained in:
parent
04553cd3de
commit
05748743bc
1 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue