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

89
Views
Kill process.exec function

I have a function to execute a process:

static async runTest() { await process.exec(`start ${currentDir}/forward.py`); }

runTest();

The python script will continue to run until it's killed, which I don't know how to do at the moment. So in short, I want to kill this process manually at some point. How I would I do this? Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The exec return value is a child-process object and you can kill it anytime by calling the .kill() function. For more info, you can refer to this

https://nodejs.org/api/child_process.html

I demonstrated the kill function using a simple timeout.

const { exec } = require('child_process');
    
    let childprocess = exec('python a.py', (error, stdout, stderr) => {
        if (error) {
            console.error(`error: ${error.message}`);
            return;
        }
    
        if (stderr) {
            console.error(`stderr: ${stderr}`);
            return;
        }
    
        console.log(`stdout:\n${stdout}`);
    });
    
    setTimeout(() => {  //Example killing
        childprocess.kill() 
    }, 2000);
about 4 years ago · Juan Pablo Isaza Report
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!