-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API to redirect
os.Inherit
ed streams globally to be consistent …
…with std streams redirections (#283) Fixes #282 Unlike usage of `System.in`/`System.out`/`System.err` programmatically, or the `scala.Console` equivalents, output from subprocesses with `os.Inherit` is not affected by `System.setIn`/`setOut`/`setErr`. This is often counterintuitive, because you expect redirecting these streams to redirect all output, only to find output from subprocess leaking through a side channel to the original process `in`/`out`/`err`. This PR adds the `os.Inherit.in`/`out`/`err` dynamic variables, which can be used to re-assign `os.Inherit` on a scoped threadlocal basis. This allows developers who use `System.setOut` or `Console.withOut` to also redirect subprocess output within the scope of the stdout redirect, without users working within those scopes to have to remember to redirect them manually at every callsite. Because we do not control `System.setOut` or `Console.withOut`, there isn't really a way for us to detect and do this automatically (e.g. redirects may happen even before OS-Lib has been even classloaded) and so we have to rely on it being opt-in. As an escape hatch, in case users do not want this behavior, we provide a `os.Inherit0` redirect which performs identically to the original `os.Inherit` even in the process of redirecting `os.Inherit.{in,out,err}` Covered by an added unit test
- Loading branch information
Showing
4 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters