Process Exit Codes
NodeJS
Easy
3 views
Problem Description
Exit with code 1 when an input number is negative.
Input Format
stdin: one integer.
Output Format
Print OK or ERROR.
Constraints
Use process.exitCode instead of process.exit.
Official Solution
const fs = require('fs');
const s = fs.readFileSync(0, 'utf8').trim();
if (!s) process.exit(0);
const n = Number(s);
if (n < 0) {
console.log('ERROR');
process.exitCode = 1;
} else {
console.log('OK');
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!