-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (40 loc) · 1.4 KB
/
index.js
File metadata and controls
44 lines (40 loc) · 1.4 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
34
35
36
37
38
39
40
41
42
43
44
const express = require('express')
const {spawn} = require('child_process');
const app = express()
const port = 3000
app.get('/', (req, res) => {
// var dataToSend;
// spawn new child process to call the python script
// const python = spawn('python', ['script1.py']);
// const python = spawn('python', ['script.py','node.js','python']);
// collect data from script
// python.stdout.on('data', function (data) {
// console.log('Pipe data from python script ...');
// dataToSend = data.toString();
// });
// in close event we are sure that stream from child process is closed
// python.on('close', (code) => {
// console.log(`child process close all stdio with code ${code}`);
// send data to browser
// res.send(dataToSend)
// });
//})
//app.listen(port, () => console.log(`Example app listening on port
//${port}!`))
var largeDataSet = [];
// spawn new child process to call the python script
const python = spawn('python', ['script2.py']);
// collect data from script
python.stdout.on('data', function (data) {
console.log('Pipe data from python script ...');
largeDataSet.push(data);
});
// in close event we are sure that stream is from child process is closed
python.on('close', (code) => {
console.log(`child process close all stdio with code ${code}`);
// send data to browser
res.send(largeDataSet.join(""))
});
})
app.listen(port, () => console.log(`Example app listening on port
${port}!`))