Visitar URL original
Execute profile commands with out-default by andyleejordan · Pull Request #3 · PowerShell/PowerShell · GitHub
Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Execute profile commands with out-default
So functions called in profile can write to the screen without any
workarounds.
  • Loading branch information
andyleejordan committed Jan 15, 2016
commit 85f21b1d9a4a8b83c32756278285b5754994a6b0
29 changes: 27 additions & 2 deletions src/Microsoft.PowerShell.Linux.Host/main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -225,6 +224,32 @@ public string Prompt(Runspace rs)
return returnVal;
}

/// <summary>
/// Runs individual commands
/// </summary>
/// <param name="command">command to run</param>
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);
}
}

/// <summary>
/// A helper class that builds and executes a pipeline that writes
/// to the default output path. Any exceptions that are thrown are
Expand Down