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

257
Vistas
calling batch file with parameter in nodejs

To run a batch file from node i am using below given code and it is working fine.

const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c','D:/somefolder/bin/tools/caprequestutil.bat']);

bat.stdout.on('data', (data) => {
  console.log('data is : '+data.toString());
});

bat.stderr.on('data', (data) => {
  console.error('error is : '+data.toString());
});

bat.on('exit', (code) => {
  console.log(`Child exited with code ${code}`);
});

It is working fine. Now i want to pass some parameter to this batch file which is not working for me. I'm trying to simply add the parameters after my .bat file as given below:

const bat = spawn('cmd.exe', ['/c','D/somefolder/bin/tools/caprequestutil.bat -id D:/somefolder/bin/tools/IdentityClient.bin -h 1234-567-8765-4532 -type STRING -attr key value -activate acdvdsfdc count https://someurl/foo -full']);

How can i add these params?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Found the answer.

The trick is to send the parameters in the form of arrays like given below

const bat = spawn('cmd.exe', ['/c',"D/somefolder/bin/tools/caprequestutil.bat", ["-id", "D:/somefolder/bin/tools/IdentityClient.bin"], ["-h", "1234-567-8765-4532"], ["-type", "STRING"], ["-attr", "key","value"], ["-activate", "acdvdsfdc "], ["count "], ["https://someurl/foo"], ["-full"]]);
about 4 years ago · Juan Pablo Isaza Denunciar
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