test('stdin errors are handled', async t => { const subprocess = execa('noop'); subprocess.stdin.emit('error', new Error('test')); await t.throwsAsync(subprocess, /test/); });
initialize() { this.rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false, }); this.rl.on('line', async (line) => this.hear(line)); }
broker1.Promise.all([broker1.start(), broker2.start()]) .then(() => broker1.waitForServices("text-converter")) .then(() => { broker1.call("text-converter.upper", process.stdin) .then(stream => { console.log("\nWrite something to the console and press ENTER. The data is transferred via streams:"); stream.pipe(process.stdout); stream.on("end", () => { broker1.logger.warn("Stream is ended. Stopping brokers..."); broker2.stop(); broker1.stop(); }); }); });
test.serial('Running `carbon-now` fails without file or stdin', async t => { try { // https://github.com/sindresorhus/get-stdin/issues/13#issuecomment-279234249 const command = exec(`node ${SCRIPT}`); command.childProcess.stdin.end(); await command; t.fail(); } catch (error) { t.pass(); } });
constructor(options = {}) { super(); this.name = options.name; this.type = options.type; this.options = options; theme(this); timer(this); this.state = new State(this); this.initial = [options.initial, options.default].find(v => v != null); this.stdout = options.stdout || process.stdout; this.stdin = options.stdin || process.stdin; this.scale = options.scale || 1; this.term = this.options.term || process.env.TERM_PROGRAM; this.margin = margin(this.options.margin); this.setMaxListeners(0); setOptions(this); }
// Use promises instead of `child_process` events const getSpawnedPromise = spawned => { return new Promise((resolve, reject) => { spawned.on('exit', (exitCode, signal) => { resolve({exitCode, signal}); }); spawned.on('error', error => { reject(error); }); if (spawned.stdin) { spawned.stdin.on('error', error => { reject(error); }); } }); }
function initCancelCatcher() { // Create interface for windows user to let them quit the program. if (process.platform === 'win32') { const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout, }); rl.on('SIGINT', function() { process.emit('SIGINT'); }); } process.on('SIGINT', () => { process.exit(1); }); }
function pauseSession(passedObject = {}) { registeredVariables = passedObject; recorder.session.start('pause'); if (!next) { let vars = Object.keys(registeredVariables).join(', '); if (vars) vars = `(vars: ${vars})`; output.print(colors.yellow(' Interactive shell started')); output.print(colors.yellow(' Use JavaScript syntax to try steps in action')); output.print(colors.yellow(` - Press ${colors.bold('ENTER')} to run the next step`)); output.print(colors.yellow(` - Press ${colors.bold('TAB')} twice to see all available commands`)); output.print(colors.yellow(` - Type ${colors.bold('exit')} + Enter to exit the interactive shell`)); output.print(colors.yellow(` - Prefix ${colors.bold('=>')} to run js commands ${colors.bold(vars)}`)); } rl = readline.createInterface(process.stdin, process.stdout, completer); rl.on('line', parseInput); rl.on('close', () => { if (!next) console.log('Exiting interactive shell....'); }); return new Promise(((resolve) => { finish = resolve; return askForStep(); })); }
describe('child_process', function() { it('should works in child_process', cb => { let cmd = fork(path.resolve(__dirname, './support/child_process.js'), [], { silent: true, }); let stdout = ''; let stderr = ''; cmd.stdout.on('data', buf => { let data = buf.toString(); stdout += data; if (data.includes('color')) cmd.stdin.write('orange\n'); }); cmd.stderr.on('data', buf => { stderr += buf.toString(); }); cmd.on('close', () => { assert(!stderr); assert(stdout.includes('color: \'orange\'')); cb(); }); }); });
process.stdin.on("end", () => run(code))
// `input` option const handleInput = (spawned, input) => { // Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852 // TODO: Remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0 if (input === undefined || spawned.stdin === undefined) { return; } if (isStream(input)) { input.pipe(spawned.stdin); } else { spawned.stdin.end(input); } }
test('you can write to child.stdin', async t => { const subprocess = execa('stdin'); subprocess.stdin.end('unicorns'); t.is((await subprocess).stdout, 'unicorns'); });
process.stdin.on("data", chunk => code += chunk)
function initCancelCatcher() { // Create interface for windows user to let them quit the program. if (process.platform === 'win32') { const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout, }); rl.on('SIGINT', function() { process.emit('SIGINT'); }); } process.on('SIGINT', () => { process.exit(1); }); }