Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!