【发布时间】:2013-08-12 06:47:37
【问题描述】:
我想通过netcat编译一些markdown帖子。这里是Makefile。
# Makefile
all: $(POSTS)
$(POST_DEST_DIR)/%.html: $(POST_SRC_DIR)/%.md | $(POST_DEST_DIR)
@nc localhost 3000 < $< > $@
@echo 'compiled $@'
.DELETE_ON_ERROR: $(POSTS)
当 TCP 服务器错误退出时,nc 无错误退出,而 Node.js nc wrapper 错误退出。这是一个 Node.js 包装脚本。
// nc.js
var client = require('net').connect(3000);
process.stdin.pipe(client);
client.pipe(process.stdout);
client.on('error', function (err) {
console.error(err.message);
process.exit(1);
});
然后
# Makefile with nc.js
$(POST_DEST_DIR)/%.html: $(POST_SRC_DIR)/%.md | $(POST_DEST_DIR)
@node nc.js < $< > $@
@echo 'compiled $@'
TCP 服务器也是用 NodeJS 编写的。我希望nc 在 TCP 服务器崩溃时以错误退出,以便立即停止 make 进程。
这是一个用于测试的 TCP 服务器。
// tcp server for error test
require('net').createServer(function(socket) {
process.exit(1);
}).listen(3000);
我已阅读 nc 手册页。但我发现做我想做的事是不可能的。我错过了什么吗?
【问题讨论】:
标签: node.js sockets tcp netcat