From 08c7d801f8e14bbae8ee7f46fa88fdda98cd3f4f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 14 Jan 2016 18:15:52 -0800 Subject: [PATCH] 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 77a56ac777..641cbf8914 100644 --- a/src/Microsoft.PowerShell.Linux.Host/main.cs +++ b/src/Microsoft.PowerShell.Linux.Host/main.cs @@ -176,8 +176,7 @@ namespace Microsoft.PowerShell.Linux.Host PSCommand[] profileCommands = HostUtilities.GetProfileCommands("PSL"); foreach (PSCommand command in profileCommands) { - this.currentPowerShell.Commands = command; - this.currentPowerShell.Invoke(); + RunCommand(command); } } finally @@ -225,6 +224,32 @@ namespace Microsoft.PowerShell.Linux.Host 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