Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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
3 changes: 2 additions & 1 deletion src/Analysis/Ast/Impl/Modules/CompiledPythonModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ private string ScrapeModule() {
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8,
RedirectStandardInput = true,
RedirectStandardOutput = true
RedirectStandardOutput = true,
RedirectStandardError = true
};
var ps = Services.GetService<IProcessServices>();

Expand Down
27 changes: 14 additions & 13 deletions src/Core/Impl/OS/PlatformProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@

namespace Microsoft.Python.Core.OS {
public sealed class PlatformProcess : IProcess {
private readonly Process _process;
public Process Process { get; private set; }

private readonly IProcessServices _ps;
public PlatformProcess(IProcessServices ps, Process process) {
_ps = ps;
_process = process;
Process = process;
}

public int Id => _process.Id;
public StreamWriter StandardInput => _process.StandardInput;
public StreamReader StandardOutput => _process.StandardOutput;
public StreamReader StandardError => _process.StandardError;
public bool HasExited => _process.HasExited;
public int ExitCode => _process.ExitCode;
public int Id => Process.Id;
public StreamWriter StandardInput => Process.StandardInput;
public StreamReader StandardOutput => Process.StandardOutput;
public StreamReader StandardError => Process.StandardError;
public bool HasExited => Process.HasExited;
public int ExitCode => Process.ExitCode;

public event EventHandler Exited {
add {
_process.EnableRaisingEvents = true;
_process.Exited += value;
Process.EnableRaisingEvents = true;
Process.Exited += value;
}
remove => _process.Exited -= value;
remove => Process.Exited -= value;
}

public bool WaitForExit(int milliseconds) => _process.WaitForExit(milliseconds);
public void Dispose() => _process.Dispose();
public bool WaitForExit(int milliseconds) => Process.WaitForExit(milliseconds);
public void Dispose() => Process.Dispose();
}
}
6 changes: 6 additions & 0 deletions src/Core/Impl/OS/ProcessServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public IProcess Start(string path) {
public async Task<string> ExecuteAndCaptureOutputAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default) {
var output = string.Empty;
var process = Start(startInfo);

if (startInfo.RedirectStandardError && process is PlatformProcess p) {
p.Process.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { });
p.Process.BeginErrorReadLine();
}

try {
output = await process.StandardOutput.ReadToEndAsync();
await process.WaitForExitAsync(30000, cancellationToken);
Expand Down