一个进程上有多个STDIN.WRITE(NodeJs)

时间:2019-02-07 14:09:05

标签: javascript node.js stdin child-process

我正在尝试在一个进程上执行一个process.stdin.Write,问题是它只能运行一次,而所有在第一个stdin.write以下的都不会运行。 例如,在这种情况下,将在第一个 setTimeout 中运行第一个 runCommand ,而不是第二个。

const  stringio = require('@rauschma/stringio');
const child = require('child_process');

const start = child.spawn(`java -Xms512M -Xmx1024M -jar ./TEST-FILE.jar`,
  [], { shell: true });


async function writeToWritable(writable, data) {
  console.log("WRITABLE", writable);
  //await stringio.streamWrite(writable, data);
  // await streamWrite(writable, 'Second line\n');
  //await stringio.streamEnd(writable);
  await writable.write(data);
  await writable.end(data);
}

async function runCommand(){
  try {
    const paramL = `/command commandParameter`;
    await writeToWritable(start.stdin, paramL);
  } catch {

  }
}

(() => {
try{
    setTimeout(runCommand, 20000);
    setTimeout(runCommand, 30000);
}catch(err){
  console.log(err);
}

})();

0 个答案:

没有答案