Run synchronous tasks using node.js on windows

I am using ffi module of node and am trying to run sync tasks on windows. I can successfully run a task using the following code.

var ffi=require('ffi')
var nativeC = new ffi.Library("Kernel32", {
"WinExec": ["int32", ["string"]]
});

nativeC.WinExec('ls -lrt');

I presume this is the way to execute sync tasks, but this code always exits after the 1st 'ls -lrt' command, if I chain a few more cmds they wont work. So is there a callback function over here, in the ffi module, or another way I can chain cmds in node.js on windows so they run in sync, one after the other. Thanks in advance.

I'm not sure you need WinExec to run a windows command. As Jonathan pointed out, ls isn't available.

However, if you want to chain commands you could use async.js and exec like this:

var
  async = require('async'); 
  exec = require('child_process').exec,
  commands = [ 'dir /w', 'echo test'];

var executeCommand = function(command, callback){
  exec(command, function (err, stdout, stderr) {
    if(err) return callback(err);
    console.log(stdout);
    callback();
  });
};

async.eachSeries(commands, executeCommand, function(err){
  console.log('error: ' + err);
});