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

186
Views
Executing a file in a different path using JS child_process

I am trying to run my C++ out file (the file is called "server") on a different path using the node.js child_process library. after I try to run it using exec or execFile, nothing seems to happen. My C++ code also requires input after running, which leads me to another problem - how do I feed input in the C++ executable file using child_process? I want to run my c++ file so seems like I'm running it on the linux terminal, but using JavaScript.

Here's my code:

export const ActivateService = (activation: boolean | undefined): boolean => {
    
    if(typeof activation == undefined){

        return false
    }

    let exec = require("child_process");

    if(activation){
        exec.exec("./server", {cwd: '/home/sourcer/repos/udpFileTransfer/AsioProject/server/udpserver/src'},
        (err: Error, stdout: string | Buffer, stderr: string | Buffer) => {
            if (err) {
                console.error(err);
                return;
            }
            console.log(stdout);
        })
    }
    else{
        exec.exec("pkill server", {cwd: "/home/sourcer/repos/udpFileTransfer/AsioProject/server/udpserver/src"},
        (err: Error, stdout: string | Buffer, stderr: string | Buffer) => {
            if (err) {
                console.error(err);
                return;
            }
            console.log(stdout);
        })
    }

    return true
}
about 4 years ago · Santiago Trujillo
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!