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

222
Visualizações
Node.js spawn is not running python command

I am trying to run a python command from Node.js v12.22.1 in a web application. This is the method that is being called in one of my controllers:

async start ({request,response,params}) {
                Log.create(request.request.headers.user,request.url())
                const { spawn } = require('child_process');
                const command = spawn('python',[process.env.BUS_PATH+'inventario/SystemDManager.py', params.name, "start"]);

                var responseData = "teste";
                command.stdout.setEncoding('utf-8');
                command.stdout.on('data', function (data){
                        responseData += data.toString();
                });
                command.stderr.on('data', function (data){
                        responseData += data.toString();
                });
                command.stdout.on('end',function(data){
                        console.log(responseData);
                });

                return responseData
        }

Variables are correctly instantiated, I have already printed them:

process.env.BUS_PATH = /home/ubuntu/

params.name = witty

So that the request command is:

python /home/ubuntu/inventario/SystemDManager.py witty start

This command runs perfectly when I type it directly into the shell console. However, nothing happens when running it through spawn. Moreover, when I change spawn arguments to:

spawn('cp',[process.env.BUS_PATH+'inventario/SystemDManager.py', "dummy.txt"]);

It works fine, it makes the file copy ... Note that my responseData variable ends with "teste", as if nothing had happened. I have even tried to change "python" to "/usr/bin/python", but everything remains the same.

Does anyone has a tip of what is going wrong that python command is no being executed?

about 4 years ago · Juan Pablo Isaza
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