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

255
Views
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 answers
Answer question

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 Report
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!