exec(command, { maxBuffer: 1024 * 1024 }, (error, stdout) => { if (error) { // Special case for robocopy, which will return non-zero error codes // when sucessful. Doc is very imprecise but <= 7 seems more or less // fine and >= 8 seems more errorish. https://ss64.com/nt/robocopy-exit.html if (command.indexOf('robocopy') === 0 && error.code <= 7) { resolve(stdout.trim()); return; } if (error.signal == 'SIGTERM') { resolve('Process was killed'); } else { const newError = new Error(`Code: ${error.code}: ${error.message}: ${stdout.trim()}`); reject(newError); } } else { resolve(stdout.trim()); } });
function addPackages() { let cmd = appendVersionsToCommand(`yarn add --dev `); child_process.exec(cmd.trim(), async (err) => { if (err) process.exit(err.code); console.log(`Done installing all versions...`); console.log("Starting benchmarks..."); await setCPUScaling(false); await runBenchmark(); await setCPUScaling(true); removePackages(); }); }
test('return error code 1 if data passed in', function (t) { const cmd = 'minicat ' + catfile + ' | node ' + binfile exec(cmd, function (err, stdout, stderr) { t.ok(stdout.length > 0, 'stdout is correct') t.equals(err.code, 1, 'correctly exits with code 1') t.end() }) })
child_process.exec('node 16-support.js '+i, function (error, stdout, stderr) { if (error) { console.log(error.stack); console.log('Error code: '+error.code); console.log('Signal received: '+error.signal); } console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); })
it('exit code 1 works when executed', (done) => { execFile( process.execPath, [GIT_BRANCH_IS, OTHER_BRANCH], (err, stdout, stderr) => { assert(err instanceof Error); assert.strictEqual(err.code, 1); assertMatch(stderr, OTHER_BRANCH_RE); assertMatch(stderr, BRANCH_CURRENT_RE); done(); }, ); });
execFile( combinedOpts.gitPath, gitArgs, { cwd: combinedOpts.cwd }, (errExec, stdout, stderr) => { if (errExec) { if (errExec.code === 1 && !stdout && !stderr) { // Not on a branch callback(null, ''); // eslint-disable-line unicorn/no-null } else { callback(errExec); } return; } // Note: ASCII space and control characters are forbidden in names // https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html callback(null, stdout.trimEnd()); // eslint-disable-line unicorn/no-null }, );
child_process.exec(exe, function (err, stdout, stderr){ if (err) { console.log("child processes failed with error code: " + err.code); } else { pushReply(message, "The bot has now sent **" + text + "** an invite."); } });
describe('code style', () => { it('should follow editorconfig conventions', function (done) { this.retries(0); this.slow(2000); exec('npm run lint:editorconfig', { cwd: path.join(__dirname, '..') }, (err, stdout) => { if (err) { // Check failed if (err.code === 1) return done(new Error(stdout)); // Command failed else return this.skip(); } done(); }); }); it('should follow eslint standards', function (done) { this.retries(0); this.slow(2000); exec('npm run lint:eslint', { cwd: path.join(__dirname, '..') }, (err, stdout) => { if (err) { // Check failed if (err.code === 1) return done(new Error(stdout)); // Command failed else return this.skip(); } done(); }); }); });
cp.exec(cmd, err => { if (err) { const isMpvFalseError = playerName === 'mpv' && err.code === 4
if (err && err.code === 1 && _.isEmpty(stdout)) { return scall(null, false);
], { timeout: 10000 }, function (error, stdout, stderr) { if (error) { if (error.code === 1) { console.log('[MediaInfo] Error: Can\'t parse file ' + fixPathname(url)); return reject(new Error(stderr)); } else if (error.code === 130) { console.log('[MediaInfo] Error: Fetch timeout ' + fixPathname(url)); return reject(new Error('Fetch timeout'));
it('exit code 1 with extra args works when executed', (done) => { execFile( process.execPath, [GIT_BRANCH_IS, OTHER_BRANCH, 'extra arg'], (err, stdout, stderr) => { assert(err instanceof Error); assert.strictEqual(err.code, 1); assert.strictEqual(stdout, ''); assertMatch(stderr, /\bargument/); done(); }, ); });