-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (31 loc) · 1.14 KB
/
index.js
File metadata and controls
37 lines (31 loc) · 1.14 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
// 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', ['python.py']);
// // collect data from script
// python.stdout.on('data', function (data) {
// console.log('Pipe data from python script ...');
// dataToSend = data.toString();
// //console.log(dataToSend)
// });
// // 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
// console.log(dataToSend)
// res.send(dataToSend)
// });
// });
// app.listen(port, () => console.log(`Example app listening on port ${port}!`));
const spawn = require('child_process').spawn;
const result = spawn('python', ['python.py']);
result.stdout.on('data', function(data) {
console.log(data.toString());
console.log(data.toString());
});
result.stderr.on('data', function(data) {
console.log(data.toString()); });