Tag: 生成

如何读取stdio的child_process.spawnSync stdout选项“inheritance”

var childProcess = cp.spawnSync(command, args, { cwd: process.cwd(), env: process.env, stdio: 'inherit', encoding: 'utf-8' }); childProcess.output总是eq [null,null,null] process.stdout.write挂钩不给我任何输出

为什么我的迭代器再次进入?

我有以下程序 – 我使用genny.js来处理asynchronousstream量控制 – 我已经尝试与suspend.js相同 – 类似的错误。 我正在使用Stripe nodejs API。 我的迭代函数似乎被调用两次 – 这是造成一个错误 – 我不明白为什么被调用两次。 这一定是一个简单的思维把戏,我没有看到。 var genny = require('genny') genny.longStackSupport = true var stripe = require("stripe")("sk_live_….") fetchCharges = genny.fn(function* (d) { console.log("Before fetchCharges") var charges = yield fetchList(d()) console.log("After fetchCharges – found ", charges.length) return true }) fetchList = genny.fn(function* (done) { console.log("before fetchList") […]

如何在node.jssubprocess模块中将消息以及从child到stdout传递给父进程?

我有一个child-process模块​​的问题,特别是与child.spawn和child.fork。 我依靠child_process.fork的文档,它说: 这是产生Node.js进程的child_process.spawn()function的特例。 除了正常的ChildProcess实例中的所有方法外,返回的对象还有一个内置的通信通道。 有关详细信息,请参阅child.send(message,[sendHandle])。 我在下面简化了我的问题: parent.js是: var cp = require('child_process'); var n = cp.fork('./child.js'); n.send({a:1}); //n.stdout.on('data',function (data) {console.log(data);}); n.on('message', function(m) { console.log("Received object in parent:"); console.log( m); }); child.js是: process.on('message', function(myObj) { console.log('myObj received in child:'); console.log(myObj); myObj.a="Changed value"; process.send(myObj); }); process.stdout.write("Msg from child"); 正如所料。 输出是: Msg from child myObj received in child: { […]

分叉一个subprocess并注入依赖

我目前有一个模块是阻塞的操作,所以我正在考虑把它变成一个subprocess,而不是叉。 如果我想这样做,那么我当然需要修改我的模块的架构。 该模块要求dependency injection通过调用模块作为一个函数,传入依赖关系,如下所示: var dependency = { name: "Bob" } require('worker')(dependency) 然后在我的worker模块中: module.exports = function (dependency) { // Outputs { name: "Bob" } console.log(dependency) } 我怎样才能把这个例子变成一个分叉的subprocess呢?