Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda