Skip to content

Fix #147: Enable native console app output in REPL #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.PowerShell.EditorServices
{
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;

/// <summary>
/// Manages the lifetime and usage of a PowerShell session.
Expand Down Expand Up @@ -114,6 +115,23 @@ public PowerShellContext()

this.Initialize(runspace);

// Use reflection to execute ConsoleVisibility.AlwaysCaptureApplicationIO = true;
Type consoleVisibilityType =
Type.GetType(
"System.Management.Automation.ConsoleVisibility, System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

if (consoleVisibilityType != null)
{
PropertyInfo propertyInfo =
consoleVisibilityType.GetProperty(
"AlwaysCaptureApplicationIO",
BindingFlags.Static | BindingFlags.Public);

if (propertyInfo != null)
{
propertyInfo.SetValue(null, true);
}
}
}

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,30 @@ await requestContext.SendResult(
await evaluateTask;
}

[Fact]
public async Task ServiceExecutesNativeCommandAndReceivesCommand()
{
OutputReader outputReader = new OutputReader(this.protocolClient);

// Execute the script but don't await the task yet because
// the choice prompt will block execution from completing
Task<EvaluateResponseBody> evaluateTask =
this.SendRequest(
EvaluateRequest.Type,
new EvaluateRequestArguments
{
Expression = "cmd.exe /c 'echo Test Output'",
Context = "repl"
});

// Skip the command line and the following newline
await outputReader.ReadLines(2);

// Wait for the selection to appear as output
await evaluateTask;
Assert.Equal("Test Output", await outputReader.ReadLine());
}

private async Task SendOpenFileEvent(string filePath, bool waitForDiagnostics = true)
{
string fileContents = string.Join(Environment.NewLine, File.ReadAllLines(filePath));
Expand Down