最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

没有打印到控制台的分叉捕获输出

IT培训 admin 14浏览 0评论

没有打印到控制台的分叉捕获输出

我试图捕获fork的console.log,而不是将其输出到控制台。我知道您可以在子进程中执行stdout('something')并在主机进程中捕获它,但是我想使console.log具有相同的行为。

例如:

主机

require('child_process').fork('child.js');

//capture console.log of child..

儿童

//natively capture this in Host
console.log('foo');
回答如下:

提供一个带有stdio属性的选项对象作为fork调用的最后一个参数。

请参见此处:https://nodejs/dist/latest-v12.x/docs/api/child_process.html#child_process_child_process_fork_modulepath_args_options

没有打印到控制台的分叉捕获输出

我试图捕获fork的console.log,而不是将其输出到控制台。我知道您可以在子进程中执行stdout('something')并在主机进程中捕获它,但是我想使console.log具有相同的行为。

例如:

主机

require('child_process').fork('child.js');

//capture console.log of child..

儿童

//natively capture this in Host
console.log('foo');
回答如下:

提供一个带有stdio属性的选项对象作为fork调用的最后一个参数。

请参见此处:https://nodejs/dist/latest-v12.x/docs/api/child_process.html#child_process_child_process_fork_modulepath_args_options

发布评论

评论列表 (0)

  1. 暂无评论