Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

474
Vistas
How can I integrate python with nodejs

I want to use python scripts with my Node.JS server, but whenever I run the node server, the python script doesn't run. It starts the server but no python runs. I think it's in this part of the code but I'm not exactly sure.

My index.js:

app.post("/readPython", (request, response) => {
 var dataToSend;
 const python = spawn('python', ['python/cookie.py'], "Kevin");

 python.stdout.on('data', function (data) {
  dataToSend = data.toString();
 });

 python.stderr.on('data', data => {
 console.error(`stderr: ${data}`);
 });

 python.on('exit', (code) => {
 console.log(`child process exited with code ${code}, ${dataToSend}`);
 response.sendFile(`${__dirname}/html/result.html`);
 });
});

My python script:

import sys

print("Hello World!")

sys.stdout.flush()

I don't know exactly what I should expect but whatever it is, the script isn't running. Any help?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

the 3rd argument (options) in spawn() should be an object. I am assuming you are trying to send Kevin as argument. It should be like

const python = spawn('python', ['helloworld.py',"Kevin"]);

python.stdout.on('data', (data)=> {

        console.log(data.toString());
       
    });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda