【发布时间】:2021-08-04 13:44:30
【问题描述】:
我正在使用 node.js 进行日志尾项目,但函数 process.createChildProcess 无法正常工作。是否有任何替代方法?
var sys = require('sys');
var filename = "test.txt";
var process=require('process')
if (!filename)
return sys.puts("Usage: node watcher.js filename");
// Look at http://nodejs.org/api.html#_child_processes for detail.
var tail = process.createChildProcess("tail", ["-f", filename]);
sys.puts("start tailing");
tail.addListener("output", function (data) {
sys.puts(data);
});
// From nodejs.org/jsconf.pdf slide 56
var http = require("http");
http.createServer(function(req,res){
res.sendHeader(200,{"Content-Type": "text/plain"});
tail.addListener("output", function (data) {
res.sendBody(data);
});
}).listen(8000);
这里出现错误:
var tail = process.createChildProcess("tail", ["-f", filename]);
^
TypeError: process.createChildProcess is not a function
任何帮助将不胜感激
文章引用:https://thoughtbot.com/blog/real-time-online-activity-monitor-example-with-node-js-and-websocket
【问题讨论】:
标签: javascript node.js process