- FILE *fp;
- fp = popen(command, "r");
- if (fp) {
- char *a;
- while (fgets(command, 1024, fp) != NULL) {
- if((a = strchr(command, '\n')))
- *a = '\0';
- if(answere_channel) {
- putsock(client, "PRIVMSG %s :%s", chan->name, command);
- } else
- reply(getTextBot(), user, "%s", command);
- }
- pclose(fp);
- } else {
- //error
- reply(getTextBot(), user, "internal bot error - please contact an administrator!");
+
+ struct neonserv_cmd_extscript_cache *cache = malloc(sizeof(*cache));
+ if (!cache) {
+ perror("malloc() failed");
+ return;
+ }
+ cache->client = client;
+ cache->textclient = getTextBot();
+ cache->event = event;
+ cache->user = user;
+ cache->chan = chan;
+ cache->answere_channel = answere_channel;
+ cache->pipe = popen(command, "r");
+ #ifndef WIN32
+ fcntl(fileno(cache->pipe), F_SETFL, O_NONBLOCK);
+ #endif
+ timeq_add(1, neonserv_cmd_extscript_callback, cache);
+}
+
+static TIMEQ_CALLBACK(neonserv_cmd_extscript_callback) {
+ struct neonserv_cmd_extscript_cache *cache = data;
+ char command[512];
+ char *a;
+ if(feof(cache->pipe)) {
+ pclose(cache->pipe);
+ free(cache);