I have a node.js script which starts a python subprocess and reads its stdout. This works as long as the python process does not try to read from stdin. Then the parent process does not get anything from the child.
I have the node.js script and two python test cases here: (both examples work if you comment the lines that try to read from stdin)
First child:
import sys
print('before')
for line in sys.stdin:
print(line)
print('after')
Second child:
import sys
print('before')
while True:
line = sys.stdin.readline()
if line != '':
print(line)
else:
break
print('after')
Parent:
const spawn = require('child_process').spawn;
let client = spawn('python', ['test1.py'], {cwd: '/tmp'});
client.stdout.on('data', (data) => {
console.log(data.toString());
});
client.stderr.on('data', (data) => {
console.log(data.toString());
});
client.on('close', () => {
console.log('close');
});
client.on('exit', () => {
console.log('exit');
});
client.on('disconnect', () => {
console.log('disconnect');
})