-
Notifications
You must be signed in to change notification settings - Fork 245
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
feat(dotnet,java): kernel process inherits host's STDERR #2248
Changes from 1 commit
6d2be36
0bbb249
480e69f
cec02a5
9fc6542
588182c
3aeb3b8
840d4cb
0bae44e
aaf1252
7ef36ba
bbcce77
83c07f1
3b123a9
6b64d20
a624312
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,7 @@ public NodeProcess(IJsiiRuntimeProvider jsiiRuntimeProvider, ILoggerFactory logg | |
StandardInputEncoding = utf8, | ||
RedirectStandardOutput = true, | ||
StandardOutputEncoding = utf8, | ||
RedirectStandardError = true, | ||
StandardErrorEncoding = utf8 | ||
UseShellExecute = false, | ||
} | ||
}; | ||
|
||
|
@@ -58,18 +57,23 @@ public NodeProcess(IJsiiRuntimeProvider jsiiRuntimeProvider, ILoggerFactory logg | |
_process.Start(); | ||
} | ||
|
||
~NodeProcess() { | ||
((IDisposable)this).Dispose(); | ||
} | ||
|
||
public TextWriter StandardInput => _process.StandardInput; | ||
|
||
public TextReader StandardOutput => _process.StandardOutput; | ||
|
||
public TextReader StandardError => _process.StandardError; | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
StandardInput.Dispose(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these not needed anymore ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Additionally, |
||
StandardOutput.Dispose(); | ||
StandardError.Dispose(); | ||
StandardInput.Close(); | ||
_process.WaitForExit(5_000); | ||
_process.Dispose(); | ||
|
||
// If Dispose() is called manually, there is no need to run the finalizer anymore, since | ||
// this only calls Dispose(). So we inform the GC about this. | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
/// <summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Amazon.JSII.Runtime.Services | ||
{ | ||
|
@@ -10,19 +9,14 @@ internal sealed class Runtime : IRuntime | |
public Runtime(INodeProcess nodeProcess) | ||
{ | ||
_nodeProcess = nodeProcess ?? throw new ArgumentNullException(nameof(nodeProcess)); | ||
if (Environment.GetEnvironmentVariable("JSII_DEBUG") != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What functionality do we lose here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, |
||
{ | ||
Task.Run(() => RedirectStandardError()); | ||
} | ||
} | ||
|
||
public string ReadResponse() | ||
{ | ||
var response = _nodeProcess.StandardOutput.ReadLine(); | ||
if (string.IsNullOrEmpty(response)) | ||
{ | ||
var errorMessage = _nodeProcess.StandardError.ReadToEnd(); | ||
throw new JsiiException("Child process exited unexpectedly: " + errorMessage); | ||
throw new JsiiException("Child process exited unexpectedly!"); | ||
} | ||
|
||
return response; | ||
|
@@ -43,13 +37,5 @@ public void WriteRequest(string request) | |
_nodeProcess.StandardInput.WriteLine(request); | ||
_nodeProcess.StandardInput.Flush(); | ||
} | ||
|
||
private void RedirectStandardError() | ||
{ | ||
while (true) | ||
{ | ||
Console.Error.WriteLine(_nodeProcess.StandardError.ReadLine()); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good change but usually has implications on being able to locate executables. Have you tested this on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseShellExecute = false
is required if you set anyRedirect*
totrue
.false
on.NET Core
(buttrue
on.NET Framework
). This is only making it explicit