'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
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source