From cc2bdee9ecdd4807ccdcc70807fb4bcce15ae9e3 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 23 Nov 2015 15:20:57 -0800 Subject: [PATCH] Add runspace test without InitialSessionState --- Microsoft.PowerShell.Linux.Host/main.cs | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Microsoft.PowerShell.Linux.Host/main.cs b/Microsoft.PowerShell.Linux.Host/main.cs index d37c17d6d2..fca695a5f3 100644 --- a/Microsoft.PowerShell.Linux.Host/main.cs +++ b/Microsoft.PowerShell.Linux.Host/main.cs @@ -25,6 +25,8 @@ namespace Microsoft.PowerShell.Linux.Host Console.WriteLine("TypeCatalog generation failed!"); } + bool runspaceTest = false; + // Custom argument parsing string initialScript = null; if (args.Length > 0) @@ -45,6 +47,11 @@ namespace Microsoft.PowerShell.Linux.Host { initialScript = arg; } + // --runspace was specified for a simple runspace test + else if (arg == "--runspace") + { + runspaceTest = true; + } // --file was specified else if (hasNext && (arg == "--file" || arg == "-f")) { @@ -72,6 +79,26 @@ namespace Microsoft.PowerShell.Linux.Host } } } + + if (runspaceTest) + { + using (var runspace = RunspaceFactory.CreateRunspace()) + { + runspace.Open(); + + using (var ps = runspace.CreatePipeline(initialScript)) + { + foreach (var result in ps.Invoke()) + { + Console.WriteLine(result); + } + } + + runspace.Close(); + } + return; + } + // TODO: check for input on stdin // Create the listener and run it @@ -215,8 +242,8 @@ namespace Microsoft.PowerShell.Linux.Host return returnVal; } - // TODO: if we are in block mode, sep the prome to ">> " - Pipeline pipeline = rs.CreatePipeline(); + // TODO: if we are in block mode, sep the prompt to ">> " + Pipeline pipeline = rs.CreatePipeline(); Command promptCommand = new Command("prompt"); pipeline.Commands.Add(promptCommand); @@ -229,6 +256,7 @@ namespace Microsoft.PowerShell.Linux.Host return returnVal; } + /// /// A helper class that builds and executes a pipeline that writes /// to the default output path. Any exceptions that are thrown are