简体   繁体   English

nodejs + shell(期望)+ child_process

[英]nodejs + shell(expect) +child_process

i have a small problem in creating javascript. 我在创建javascript时遇到了小问题。

i have a js which spawn shell script(expect, which ssh another computer, and send some data back to nodejs. 我有一个生成外壳程序脚本的js(期望,它会切换到另一台计算机,然后将一些数据发送回nodejs。

i have problem in multithreading. 我在多线程中有问题。

var cons = spawn('./somescript');
var content;
cons.stdout.on('data', function(block)
{
content += block;
mrdialist = JSON.parse(block);
....
console.log("" + block);
});
console.log("hjdfsdf");
here is some actions with loaded and parced data.

but when i try to execute jscript, it start from the beginning, and make all actions through loading data without loading and parsing, how can i continue execution of the code onlu, after execution 但是,当我尝试执行jscript时,它从头开始,并通过不加载和解析就加载数据来执行所有操作,执行后如何继续在onlu上执行代码

    console.log("" + block);
    });
    console.log("hjdfsdf");

spawn will be execute asynchrounsly. 生成将被异步执行。 you have to execute your code when event close will be emit. 当事件close发出时,您必须执行代码。

var cons = spawn('./somescript');
var content;
cons.stdout.on('data', function(block)
{
content += block;
mrdialist = JSON.parse(block);
....
console.log("" + block);
});

cons.on('close', function () {
    console.log("hjdfsdf");
    // manipulate content
    console.log("content", content);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM