1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 var common = require('../common');
23 var assert = require('assert');
25 var spawn = require('child_process').spawn;
26 var is_windows = process.platform === 'win32';
28 var cat = spawn(is_windows ? 'more' : 'cat');
29 cat.stdin.write('hello');
31 cat.stdin.write('world');
33 assert.ok(cat.stdin.writable);
34 assert.ok(!cat.stdin.readable);
42 var gotStdoutEOF = false;
44 cat.stdout.setEncoding('utf8');
45 cat.stdout.on('data', function(chunk) {
46 console.log('stdout: ' + chunk);
50 cat.stdout.on('end', function() {
55 var gotStderrEOF = false;
57 cat.stderr.on('data', function(chunk) {
58 // shouldn't get any stderr output
62 cat.stderr.on('end', function(chunk) {
67 cat.on('exit', function(status) {
68 console.log('exit event');
72 cat.on('close', function () {
75 assert.equal('hello world\r\n', response);
77 assert.equal('hello world', response);
81 process.on('exit', function() {
82 assert.equal(0, exitStatus);
85 assert.equal('hello world\r\n', response);
87 assert.equal('hello world', response);