11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
41cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst { join } = require('path');
71cb0ef41Sopenharmony_ciconst childProcess = require('child_process');
81cb0ef41Sopenharmony_ciconst fs = require('fs');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst stdoutScript = fixtures.path('echo-close-check.js');
111cb0ef41Sopenharmony_ciconst tmpFile = join(tmpdir.path, 'stdin.txt');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst cmd = `"${process.argv[0]}" "${stdoutScript}" < "${tmpFile}"`;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst string = 'abc\nümlaut.\nsomething else\n' +
161cb0ef41Sopenharmony_ci               '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,' +
171cb0ef41Sopenharmony_ci               '疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、' +
181cb0ef41Sopenharmony_ci               '云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' +
191cb0ef41Sopenharmony_ci               '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' +
201cb0ef41Sopenharmony_ci               '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
211cb0ef41Sopenharmony_ci               '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
221cb0ef41Sopenharmony_ci               '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' +
231cb0ef41Sopenharmony_ci               '采用封建制和郡县制并存的制度,' +
241cb0ef41Sopenharmony_ci               '它的建立保证了秦末乱世岭南地区社会秩序的稳定,' +
251cb0ef41Sopenharmony_ci               '有效的改善了岭南地区落后的政治、##济现状。\n';
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_citmpdir.refresh();
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciconsole.log(`${cmd}\n\n`);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_cifs.writeFileSync(tmpFile, string);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_cichildProcess.exec(cmd, common.mustCall(function(err, stdout, stderr) {
351cb0ef41Sopenharmony_ci  fs.unlinkSync(tmpFile);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  assert.ifError(err);
381cb0ef41Sopenharmony_ci  assert.strictEqual(stdout, `hello world\r\n${string}`);
391cb0ef41Sopenharmony_ci  assert.strictEqual(stderr, '');
401cb0ef41Sopenharmony_ci}));
41