-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (25 loc) · 857 Bytes
/
index.js
File metadata and controls
34 lines (25 loc) · 857 Bytes
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
34
const fs = require('fs');
const { spawn, fork } = require('child_process');
// create fifo
// this will create a "file" in this folder that is invisible on macOS by default. Run ls -l to see it.
let fifo = spawn('mkfifo', ['testfifo']);
// this occurs after fifo is created
fifo.on('exit', function(status) {
// have to pass a file descriptor for FIFOs for some reason, file name won't work
const fd = fs.openSync('./testfifo', 'r+');
let fifoRs = fs.createReadStream(null, { fd });
// start separate node.js process
fork(require.resolve('./write-to-fifo'));
// get a hello from C++
setTimeout(() => {
spawn('./hello');
}, 1500);
// get a hello from bash
setTimeout(() => {
spawn('./hello.sh');
}, 2500);
// log out when it's been written to
fifoRs.on('data', data => {
console.log(data.toString());
});
});