Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

process.stdout and process.stderr get flushed out-of-order in Windows when piped #6249

Closed
cowboy opened this issue Sep 20, 2013 · 9 comments
Closed
Labels

Comments

@cowboy
Copy link

cowboy commented Sep 20, 2013

When process.stdout and process.stderr are not piped, writes to them are output in order, as written. When piped, they are written out-of-order. While there seems to be a workaround for the draining issue in #3584, I can't figure out a workaround for this issue.

Given this translation-party.js file:

// Test code
var words = "this is a happy test sentence of words".split(" ");

// Test code
for (var i = 0; i < words.length; i += 2) {
  process.stdout.write("[stdout] " + words[i] + "\r\n");
  process.stderr.write("[stderr] " + words[i + 1] + "\r\n");
}

In Windows, I see the following behavior.

C:\test>node translation-party.js
[stdout] this
[stderr] is
[stdout] a
[stderr] happy
[stdout] test
[stderr] sentence
[stdout] of
[stderr] words

C:\test>node translation-party.js | find "std"
[stdout] this
[stderr] is
[stderr] happy
[stderr] sentence
[stderr] words
[stdout] a
[stdout] test
[stdout] of

Can you guys please prioritize fixing these stdio piping issues?

@pipobscure
Copy link

try

node translate.js 2>&1 | find std

because what you are doing is letting node output to stderr and find to std out if I'm not mistaken.

On 20 Sep 2013, at 14:33, Ben Alman notifications@github.com wrote:

When process.stdout and process.stderr are not piped, writes to them are output in order, as written. When piped, they are written out-of-order. While there seems to be a workaround for the draining issue in #3584, I can't figure out a workaround for this issue.

Given this translation-party.js file:

// Test code
var words = "this is a happy test sentence of words".split(" ");

// Test code
for (var i = 0; i < words.length; i += 2) {
process.stdout.write("[stdout] " + words[i] + "\r\n");
process.stderr.write("[stderr] " + words[i + 1] + "\r\n");
}
In Windows, I see the following behavior.

C:\Users\Administrator\Desktop\grunt>node translation-party.js
[stdout] this
[stderr] is
[stdout] a
[stderr] happy
[stdout] test
[stderr] sentence
[stdout] of
[stderr] words

C:\Users\Administrator\Desktop\grunt>node translation-party.js | find "std"
[stdout] this
[stderr] is
[stderr] happy
[stderr] sentence
[stderr] words
[stdout] a
[stdout] test
[stdout] of
Can you guys please prioritize fixing these stdio piping issues?


Reply to this email directly or view it on GitHub.

@cowboy
Copy link
Author

cowboy commented Sep 20, 2013

Derp. Thanks!

C:\test>node translation-party.js 2>&1 | find "std"
[stdout] this
[stderr] is
[stdout] a
[stderr] happy
[stdout] test
[stderr] sentence
[stdout] of
[stderr] words

I'll close the issue. But PLZ OMG FIX #3584 THX

@nimhawk
Copy link

nimhawk commented Sep 25, 2013

Run using cmd.exe and periodically get it out of order...

C:\devenv\workspace\sandbox\node-exit\test\fixtures>node translation-party.js 2>
&1 | grep "std"
[stdout] this
[stderr] is
[stderr] happy
[stdout] a
[stderr] sentence
[stdout] test
[stderr] words
[stdout] of

C:\devenv\workspace\sandbox\node-exit\test\fixtures>

@bdukes
Copy link

bdukes commented Sep 25, 2013

In powershell, I occasionally get out of order results (I'm piping to % { "$_" } per http://stackoverflow.com/a/12866669/2688, to get Powershell to avoid thinking the stderr output means the command failed):

C:\tmp\node-issue-6249
> node .\translation-party.js 2>&1 | % { "$_" }
[stdout] this
[stderr] is
[stdout] a
[stderr] happy
[stdout] test
[stderr] sentence
[stderr] words
[stdout] of
C:\tmp\node-issue-6249
> node .\translation-party.js 2>&1 | % { "$_" }
[stdout] this
[stderr] is
[stdout] a
[stderr] happy
[stdout] test
[stdout] of
[stderr] sentence
[stderr] words

@cowboy
Copy link
Author

cowboy commented Sep 25, 2013

I'm going to reopen this, it might be a real bug.

@cowboy cowboy reopened this Sep 25, 2013
@pipobscure
Copy link

I dont think there is actually a way to ensure the streams are in sync unless you ensure between writes that the receiving app has had a processing timeslice and has read its fd.

Because the other side might actually poll in reverse/random/unknown order.

I might be totally off base. I have been way too far away from the OS these days.

@cowboy
Copy link
Author

cowboy commented Sep 25, 2013

Having stdout and stderr output in a predictable order qualifies as "really, really important" for something that bothers to make a distinction between stdout and stderr.

@FeodorFitsner
Copy link

You might want to check this: mapnik/node-mapnik#257 (comment)

@Fishrock123
Copy link

Fixed by nodejs/node@20176a9 a couple years ago.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants