Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

477
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda