From 85f21b1d9a4a8b83c32756278285b5754994a6b0 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 14 Jan 2016 18:15:52 -0800 Subject: [PATCH 1/2] Execute profile commands with out-default So functions called in profile can write to the screen without any workarounds. --- src/Microsoft.PowerShell.Linux.Host/main.cs | 29 +++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Linux.Host/main.cs b/src/Microsoft.PowerShell.Linux.Host/main.cs index 77a56ac777b..641cbf8914c 100644 --- a/src/Microsoft.PowerShell.Linux.Host/main.cs +++ b/src/Microsoft.PowerShell.Linux.Host/main.cs @@ -176,8 +176,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 +224,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 From f3c617b143cb038aceeef2016f8f89352ec8d94c Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Tue, 12 Jan 2016 21:18:16 -0800 Subject: [PATCH 2/2] Added banner to profile, removed from main --- src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 | 10 ++++++++++ src/Microsoft.PowerShell.Linux.Host/main.cs | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) 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 641cbf8914c..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(); } }