11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst spawn = require('child_process').spawn;
51cb0ef41Sopenharmony_ciconst stream = require('stream');
61cb0ef41Sopenharmony_ciconst fs = require('fs');
71cb0ef41Sopenharmony_ciconst path = require('path');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// require('internal/fs/utils').SyncWriteStream is used as a stdio
101cb0ef41Sopenharmony_ci// implementation when stdout/stderr point to files.
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
131cb0ef41Sopenharmony_ci  // Note: Calling console.log() is part of this test as it exercises the
141cb0ef41Sopenharmony_ci  // SyncWriteStream#_write() code path.
151cb0ef41Sopenharmony_ci  console.log(JSON.stringify([process.stdout, process.stderr].map((stdio) => ({
161cb0ef41Sopenharmony_ci    instance: stdio instanceof stream.Writable,
171cb0ef41Sopenharmony_ci    readable: stdio.readable,
181cb0ef41Sopenharmony_ci    writable: stdio.writable,
191cb0ef41Sopenharmony_ci  }))));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  return;
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
251cb0ef41Sopenharmony_citmpdir.refresh();
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciconst filename = path.join(tmpdir.path, 'stdout');
281cb0ef41Sopenharmony_ciconst stdoutFd = fs.openSync(filename, 'w');
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciconst proc = spawn(process.execPath, [__filename, 'child'], {
311cb0ef41Sopenharmony_ci  stdio: ['inherit', stdoutFd, stdoutFd ]
321cb0ef41Sopenharmony_ci});
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ciproc.on('close', common.mustCall(() => {
351cb0ef41Sopenharmony_ci  fs.closeSync(stdoutFd);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  assert.deepStrictEqual(JSON.parse(fs.readFileSync(filename, 'utf8')), [
381cb0ef41Sopenharmony_ci    { instance: true, readable: false, writable: true },
391cb0ef41Sopenharmony_ci    { instance: true, readable: false, writable: true },
401cb0ef41Sopenharmony_ci  ]);
411cb0ef41Sopenharmony_ci}));
42