Skip to content

Commit bc3c521

Browse files
committed
Updating README.
1 parent 0e2d0be commit bc3c521

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

README.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
A replacement for process.exit that ensures stdio are fully drained before exiting.
44

5-
If you're familiar with the seemingly never-ending saga in joyent/node#3584, you already know that Node.js behaves differently on Windows when pipe-redirecting `stdout` or `stderr` vs just displaying output in the shell. Well, this module attempts to work around the issue by waiting until those streams have been completely drained before actually calling `process.exit`.
5+
To make a long story short, if `process.exit` is called on Windows, script output is often truncated when pipe-redirecting `stdout` or `stderr`. This module attempts to work around this issue by waiting until those streams have been completely drained before actually calling `process.exit`.
66

7-
Based on some code by @vladikoff.
7+
See [Node.js issue #3584](https://github.com/joyent/node/issues/3584) for further reference.
8+
9+
Tested in OS X 10.8, Windows 7 on Node.js 0.8.25 and 0.10.18.
10+
11+
Based on some code by [@vladikoff](https://github.com/vladikoff).
812

913
## Getting Started
1014
Install the module with: `npm install exit`
1115

1216
```javascript
1317
var exit = require('exit');
1418

15-
// These lines should appear in the output.
19+
// These lines should appear in the output, EVEN ON WINDOWS.
1620
console.log("foo");
1721
console.error("bar");
1822

@@ -24,6 +28,38 @@ console.log("foo");
2428
console.error("bar");
2529
```
2630

31+
## Don't believe me? Try it for yourself.
32+
33+
In Windows, clone the repo and cd to the `test\fixtures` directory. The only difference between [log.js](test/fixtures/log.js) and [log-broken.js](test/fixtures/log-broken.js) is that the former uses `exit` while the latter calls `process.exit` directly.
34+
35+
```
36+
C:\node-exit\test\fixtures>node log.js 0 10 stdout stderr 2>&1 | find "std"
37+
[stdout] testing 0
38+
[stderr] testing 0
39+
[stdout] testing 1
40+
[stderr] testing 1
41+
[stdout] testing 2
42+
[stderr] testing 2
43+
[stdout] testing 3
44+
[stderr] testing 3
45+
[stdout] testing 4
46+
[stderr] testing 4
47+
[stdout] testing 5
48+
[stderr] testing 5
49+
[stdout] testing 6
50+
[stderr] testing 6
51+
[stdout] testing 7
52+
[stderr] testing 7
53+
[stdout] testing 8
54+
[stderr] testing 8
55+
[stdout] testing 9
56+
[stderr] testing 9
57+
58+
C:\node-exit\test\fixtures>node log-broken.js 0 10 stdout stderr 2>&1 | find "std"
59+
60+
C:\node-exit\test\fixtures>
61+
```
62+
2763
## Contributing
2864
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
2965

0 commit comments

Comments
 (0)