From f730e07455d01d0975810f822b80d51c235c2aa9 Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Mon, 7 Oct 2024 23:41:30 +0200 Subject: [PATCH] Running ps1 files --- src/Vm/InstructionExecutor.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Vm/InstructionExecutor.cs b/src/Vm/InstructionExecutor.cs index f98d1de..f7eb346 100644 --- a/src/Vm/InstructionExecutor.cs +++ b/src/Vm/InstructionExecutor.cs @@ -752,11 +752,19 @@ private void CallProgram( var fileName = ((RuntimeProgramFunction)_stack.Pop()).ProgramName; var process = new Process(); var shouldRedirectOutput = props.HasFlag(ProgramCallProps.RedirectOutput) || !isRoot; + fileName = fileName.StartsWith("./") + ? Path.Combine(ShellEnvironment.WorkingDirectory, fileName) + : fileName; + var prefixArguments = new List(); + if (OperatingSystem.IsWindows() && fileName.EndsWith(".ps1")) + { + prefixArguments = ["-NoProfile", "-ExecutionPolicy", "ByPass", "-File", fileName]; + fileName = "powershell.exe"; + } + process.StartInfo = new ProcessStartInfo { - FileName = fileName.StartsWith("./") - ? Path.Combine(ShellEnvironment.WorkingDirectory, fileName) - : fileName, + FileName = fileName, RedirectStandardOutput = shouldRedirectOutput, RedirectStandardError = props.HasFlag(ProgramCallProps.RedirectError), RedirectStandardInput = pipedValue != null, @@ -770,9 +778,10 @@ private void CallProgram( } // Arguments - var arguments = (RuntimeList)_stack.Pop(); - foreach (var arg in arguments) - process.StartInfo.ArgumentList.Add(arg.ToString() ?? ""); + var arguments = ((RuntimeList)_stack.Pop()) + .Select(x => x.ToString() ?? ""); + foreach (var arg in prefixArguments.Concat(arguments)) + process.StartInfo.ArgumentList.Add(arg); var processContext = new ProcessContext( process,