Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda