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
Text written to piped stdout/stderr is printed out of order #17
Comments
By default, stdout and error are always captured. What may occur is the sub process writes to stdout, stderr, then stdout, but only then does the process running dax start reading which could read all the data in stdout at once, then after all the data in stderr. I don't think there's any way around this since stdout and stderr are two separate pipes. I think the same issue could occur in zx, but maybe the chances are lower because node uses callbacks? https://github.com/google/zx/blob/700bd4cae2ce564aa477b2501b1916c2a9041a85/src/core.ts#L208-L222
Yeah, if you inherit then it the subprocess will write directly to the deno process's stdout and err, which won't rely on the javascript code waking up and reading from stdout and stderr, storing it, then outputing. If you want to change the default you can do: import {
build$,
CommandBuilder,
} from "...";
const commandBuilder = new CommandBuilder()
.stdout("inherit")
.stderr("inherit");
const $ = build$({ commandBuilder }); |
@dsherret Got it, this makes sense, and I bet you're right in your guess about Out of curiosity, did you consider making the Thanks for the info and follow up on this - cheers! Edit: I just ran a test with |
I think that would be better because of the existence of the "helper" functions (like |
Awesome! Thanks for taking a look at this and as always, thank you very much for your work on this (and the Deno ecosystem) 😄 |
You're welcome! This is now released in 0.11.0. I'm not sure if there's anything we can do to mitigate this when capturing the output unfortunately. |
Nice! Yea, given my new understanding of how this works, I suspect you're right. I will go ahead and close this issue as "that's just kinda how it works" 😄 Fortunately, the new default provides the behavior I expected intuitively, so that's great! Cheers! |
I believe my change in... ...should mitigate this issue. I was using async writers everywhere, but it wasn't necessary. |
When using the default
stdout
/stderr
streams for a$
command, text written to the different streams in a particular order can appear out of order when printed.Example
if I run
deno run -A main.ts
on the following file:the output printed to the terminal is:
By contrast, if I inherit the streams from the parent process as:
then the output to the terminal is:
Is this "out of order" output because the streams are buffered when not inherited?
The text was updated successfully, but these errors were encountered: