Skip to content

Commit

Permalink
Running ps1 files
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Oct 7, 2024
1 parent dd8b78f commit f730e07
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Vm/InstructionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
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,
Expand All @@ -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,
Expand Down

0 comments on commit f730e07

Please sign in to comment.