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