-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspawn.js
More file actions
33 lines (27 loc) · 1.11 KB
/
Copy pathspawn.js
File metadata and controls
33 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { spawn , spawnSync } = require('child_process');
//https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
let top = spawn("top",["-b", "-d", 3, "-n", 4, "-p", 0], {detached: true})
top.on('error', (err) => {
console.log(`TOP Spawn Error`, err);
})
top.stdout.on('data', (data) => {
let lines = data.toString().split("\n")
//console.log(lines.length);
//console.log("-----------------------------------------------------------");
if (lines.length >= 10){
console.log(lines)
lines.forEach((item, i) => {
// parseOutput
});
} else {
//console.log(`incomplete TOP data` )
}
});
top.stderr.on('data', (data) => {
console.log(`TOP ERROR: ${data.toString()}`)
});
top.on('exit', (code) => {
console.log(`TOP exited with code ${code}`);
});
//*** Add spawnSync example
//https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options