我还在学习C ++,刚刚开始使用node,我在C ++中创建了一个用于在聊天中接收消息的IRC客户端,然后我想通过使用来自生成子进程的流stdout从Node.js中获取这些客户端。
但是我没有收到来自exe的输出。 我在Node.js脚本中收到exe输出的唯一一次是我结束永久循环(irc_run),但是我认为这会产生异步,因为它是异步生成的?
正常启动时,exe工作正常,显示发送的所有消息。
使用的图书馆: http://sourceforge.net/projects/libircclient/
Consoleapplication1.cpp
#include "stdafx.h"
#include "libircclient.h"
void event_numeric(irc_session_t *session, unsigned int event,
const char *origin, const char **params,
unsigned int count) {
return;
}
void event_connect(irc_session_t *session, const char *event,
const char *origin, const char **params,
unsigned int count) {
irc_cmd_join(session, "#username", 0);
}
void event_channel(irc_session_t *session, const char *event,
const char *origin, const char **params,
unsigned int count) {
printf("%s\n", params[1]);
irc_disconnect(session);
}
int main() {
printf("Connected and setup.\n");
irc_callbacks_t callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.event_connect = event_connect;
callbacks.event_numeric = event_numeric;
callbacks.event_channel = event_channel;
irc_session_t *session = irc_create_session(&callbacks);
if (irc_connect(session, "irc.twitch.tv", 6667,
"password", "username",
"username", "username")) {
return 1;
}
if (irc_run(session)) {
}
return 0;
}
Debug.js:
var spawn = require('child_process').spawn;
var irc = spawn('C:/irc/ConsoleApplication1.exe');
irc.stdout.on('data', function(data) {
console.log(String(data));
});
irc.stderr.on('data', function(data) {
console.log(String(data));
});
irc.on('error', function(error) {
console.log(error);
});