How do I execute a dos command in a separate thread in nodejs?

I use

var version = shell.exec('D:\\prompt.bat', {silent:false}).output;

      

Shelljs npm module to run .bat file

this .bat file opens iexplore.exe and Internet explorer opens

BUT  The problem is that it runs on one thread until IE is closed, my server is waitng and does not process any further request,

so everyone can suggest me how to run the DOS command on a separate thread so that it doesn't affect my server.

Thank you in advance.:)

+3


source to share


2 answers


You can actually use something else like child_process or exec to create an async process, but node.js will still not exit until the child process is finished or exited . Although it will continue to execute.

Example ( source ):

var exec = require('exec');

exec(['D:\\prompt.bat'], function(err, out, code) {
  if (err instanceof Error)
    throw err;
  process.stderr.write(err);
  process.stdout.write(out);
  process.exit(code);
});

      




Alternative and simple method: you can try running async CMD code which solves the problem not in node.js but in script.

For example, change the line to:

var version = shell.exec('start D:\\prompt.bat', {silent:false}).output;

      

Or you can add a command start

inside prompt.bat

.

+1


source


I found the answer to my second question in a comment myself:



instead of c: \ ... something uses c: /. :)

0


source







All Articles