Skip to content

Commit 30e5020

Browse files
committed
refactor: cp script.js, import argv, stdout, stdin, exit from node:process
1 parent 4a9cc25 commit 30e5020

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/cp/files/script.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { EOL } from 'node:os';
22

3-
const args = process.argv.slice(2);
3+
import { argv, stdout, stdin, exit } from 'node:process';
4+
5+
const args = argv.slice(2);
46

57
console.log(`Total number of arguments is ${args.length}`);
68
console.log(`Arguments: ${JSON.stringify(args)}${EOL}`);
79

810
const echoInput = (chunk) => {
911
const chunkStringified = chunk.toString();
10-
if (chunkStringified.includes('CLOSE')) process.exit(0);
11-
process.stdout.write(`Received from master process: ${chunk.toString()}${EOL}`)
12+
13+
if (chunkStringified.includes('CLOSE')) {
14+
exit(0);
15+
}
16+
17+
stdout.write(`Received from master process: ${chunk.toString()}${EOL}`)
1218
};
1319

14-
process.stdin.on('data', echoInput);
20+
stdin.on('data', echoInput);

0 commit comments

Comments
 (0)