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

227
Vistas
Why is spawn not working when being called from a javascript function?

I was using spawn to run a python script from a javascript function but it is not working.

const getUserById = async (req, res) => {
  const user = await Users.findOne({chatId: req.params.chatId});
  const result = await JSON.parse(JSON.stringify(user));
  console.log(result.chatName, result.chatId);
  /* result.temp = `temp_${result.chatId}`; */
  const { spawn } = require('child_process');
  const python = spawn('python', ['temp.py', user.chatName, user.chatId]);
  python.stdout.on('data', function (data) {
    console.log(data.toString());
    result.message = data.toString();
    res.json(result);
  });
}

temp.py file:

import sys

name = sys.argv[1]
chatID = sys.argv[2]
sys.stdout.write('{a} {b}'.format(a=name, b=chatID))

But independently they are working perfectly. What is the solution?

Note: They are present in the same directory. result.chatName and result.chatId are also getting logged to the console, and the main issue is occurring after that.

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