0

I have 2 files one(readlines.js) is a script that read file lines row by row and the second(test.txt) file contain the lines that the script should execute like:

node /usr/local/server/test/CLI-test.js functionName ARG1 ARG2 ARG3 ARG4 ARG5

only after this code is finish I want to read the next line in test.txt but its seems that all operation execution in the same time .

this is my code in readlines.js

var fs = require('fs'), readline = require('readline');
var exec = require('child_process').exec, child;
var fileTest = process.argv[2] != "" ? './test/'+process.argv[2] : './test/test.txt'; 
var rd = readline.createInterface({
       input: fs.createReadStream(fileTest),
       output: process.stdout,
       console: false
});
rd.on('line', function(line) {
    console.log(line);
    executeCommand(line);
});
function executeCommand(line){
  exec('sudo ' + line,{maxBuffer: 1024 * 500000000}, (err, stdout, stderr) => {
  if (err) {
    console.error(`exec error: ${err}`);
    return;
  }
    console.log(`Number of files ${stdout}`);
  });
}

moreover I found out that all operations happen all together because the buffer was not big enough.

shaharnakash
  • 675
  • 3
  • 11
  • 39

0 Answers0