diff --git a/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 b/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 index 3bb4ea9a6ef..80425881d01 100644 --- a/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 +++ b/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 @@ -13,3 +13,13 @@ function prompt invoke-expression $str } } + +function banner +{ + "`nPowerShell for Linux interactive console" + "========================================" + "- Type 'get-help' for help" + "- Type 'exit' to exit`n" +} + +banner diff --git a/src/Microsoft.PowerShell.Linux.Host/main.cs b/src/Microsoft.PowerShell.Linux.Host/main.cs index 77a56ac777b..35e4f524bb0 100644 --- a/src/Microsoft.PowerShell.Linux.Host/main.cs +++ b/src/Microsoft.PowerShell.Linux.Host/main.cs @@ -79,16 +79,6 @@ public static void Main(string[] args) // only run if there was no script file passed in if (initialScript == null) { - // Display the welcome message. - Console.WriteLine(); - Console.WriteLine("PowerShell for Linux interactive console"); - Console.WriteLine("========================================"); - Console.WriteLine(); - Console.WriteLine("Current status:"); - Console.WriteLine("- Type 'exit' to exit"); - Console.WriteLine("- Utility and Management cmdlet modules are loadable"); - Console.WriteLine(); - listener.Run(); } } @@ -176,8 +166,7 @@ public Listener(string initialScript) PSCommand[] profileCommands = HostUtilities.GetProfileCommands("PSL"); foreach (PSCommand command in profileCommands) { - this.currentPowerShell.Commands = command; - this.currentPowerShell.Invoke(); + RunCommand(command); } } finally @@ -225,6 +214,32 @@ public string Prompt(Runspace rs) return returnVal; } + /// + /// Runs individual commands + /// + /// command to run + internal void RunCommand(PSCommand command) + { + if (command == null) + { + return; + } + + command.AddCommand("out-default"); + command.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); + + this.currentPowerShell.Commands = command; + + try + { + this.currentPowerShell.Invoke(); + } + catch (RuntimeException e) + { + this.ReportException(e); + } + } + /// /// A helper class that builds and executes a pipeline that writes /// to the default output path. Any exceptions that are thrown are