From 2d1b01a0a345715f4c2f480cc3e359af6fe8f0cb Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 10 Aug 2024 15:19:46 +0800 Subject: [PATCH] fix of `PSScriptRoot` --- src/programFrames/default.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/programFrames/default.cs b/src/programFrames/default.cs index a386ccdc..7c820ade 100644 --- a/src/programFrames/default.cs +++ b/src/programFrames/default.cs @@ -1943,18 +1943,20 @@ public PSRunner() { this.PSRunSpace.SessionStateProxy.SetVariable("PSEXEscript", script); } } - /* - #if !Pwsh20 + script = "function PSEXEMainFunction{"+script+"}"; + #if Pwsh20 + this.pwsh.AddScript(script); + #else { Token[] tokens; ParseError[] errors; ScriptBlockAst AST = Parser.ParseInput(script, exepath, out tokens, out errors); + this.PSRunSpace.SessionStateProxy.SetVariable("PSEXEIniter", AST.GetScriptBlock()); if(errors.Length > 0) throw new System.InvalidProgramException(errors[0].Message); + this.pwsh.AddScript(".$PSEXEIniter"); } #endif - */ - this.pwsh.AddScript("function PSEXEMainFunction{"+script+"}"); } ~PSRunner() { this.pwsh.Dispose();