Process Spawns With "stdio: 'inherit' " But Not "stdio: 'pipe' "

I’m trying to pipe the console output of a child Python process to a parent Node.js process. I’m able to spawn a Python process successfully, and the output from the Node parent process successfully is outputted live to the webpage.

However, I can’t send the output from the child process (Python script). The Python script successfully launches if I use the parameter "stdio: ‘inherit’", but I require "stdio: ‘pipe’", to output the terminal, and for some reason it doesn’t work.

Server Code

app.post('/clientwebpageoutput', function(req,res) {     var io = require('socket.io')(http);     var child = require('child_process');      var events = require('events');     var eventEmitter = new events.EventEmitter();     eventEmitter.on('logging', function(message) {       io.emit('log_message', message);     });     io.on('connection', function(socket){         console.log('Before process begins');         var python_process = child.spawn( 'python3', ['snowboymultiplemodels.py'], {stdio: 'pipe'});          var chunk = '';         python_process.stdout.on('data', function(data){             chunk += data             socket.emit('newdata', chunk);         } );         python_process.stderr.on('data', function (data) {             console.log('Failed to start child process.');         }) });     // Override console.log     var originConsoleLog = console.log;     console.log = function(data) {       eventEmitter.emit('logging', data);       originConsoleLog(data);     };     res.render('clientwebpageoutput'); //,output); });  

Client (successfully outputs stderr):

<script src="/socket.io/socket.io.js"></script> <script>       $(function () {         var socket = io();         socket.on('log_message', function(msg){          $('#messages').append($('<li>').text(msg));         });       }); </script> 

Why does the process not spawn? The terminal always shows the error message created above in stderr ("Failed to start child process").

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.