I want to compile some markdown posts thorough netcat. Here is Makefile.
# Makefile
all: $(POSTS)
$(POST_DEST_DIR)/%.html: $(POST_SRC_DIR)/%.md | $(POST_DEST_DIR)
@nc localhost 3000 < $< > $@
@echo 'compiled $@'
.DELETE_ON_ERROR: $(POSTS)
When TCP server exit with error, nc exit without error while Node.js nc wrapper exit with error. Here is a Node.js wrapper script.
// 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);
});
An then
# Makefile with nc.js
$(POST_DEST_DIR)/%.html: $(POST_SRC_DIR)/%.md | $(POST_DEST_DIR)
@node nc.js < $< > $@
@echo 'compiled $@'
The TCP server is also written in NodeJS. I want nc to exit with error when TCP server crashes in order to stop make process immediately.
Here is a TCP server for test.
// tcp server for error test
require('net').createServer(function(socket) {
process.exit(1);
}).listen(3000);
I've read nc man page. But I found it's impossible to do what I want to do. Am I missing something?