2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-09-29 03:55:59 +02:00
|
|
|
const common = require('../common');
|
2012-06-20 19:28:44 +02:00
|
|
|
|
|
|
|
// simulate `cat readfile.js | node readfile.js`
|
|
|
|
|
2017-07-16 09:07:33 +02:00
|
|
|
if (common.isWindows || common.isAIX)
|
2016-09-29 03:30:32 +02:00
|
|
|
common.skip(`No /dev/stdin on ${process.platform}.`);
|
2012-06-20 19:28:44 +02:00
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
const assert = require('assert');
|
2016-09-29 03:55:59 +02:00
|
|
|
const fs = require('fs');
|
2012-06-20 19:28:44 +02:00
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const dataExpected = fs.readFileSync(__filename, 'utf8');
|
2012-06-20 19:28:44 +02:00
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
fs.readFile('/dev/stdin', function(er, data) {
|
2017-01-07 01:11:07 +01:00
|
|
|
assert.ifError(er);
|
2012-06-20 19:28:44 +02:00
|
|
|
process.stdout.write(data);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const f = JSON.stringify(__filename);
|
|
|
|
const node = JSON.stringify(process.execPath);
|
|
|
|
const cmd = `cat ${f} | ${node} ${f} child`;
|
2012-06-20 19:28:44 +02:00
|
|
|
exec(cmd, function(err, stdout, stderr) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2016-09-17 12:32:33 +02:00
|
|
|
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
|
|
|
|
assert.strictEqual(stderr, '', 'it does not write to stderr');
|
2012-06-20 19:28:44 +02:00
|
|
|
console.log('ok');
|
|
|
|
});
|