made cmd_extscript WIN32 compatible
[NeonServV5.git] / src / cmd_neonserv_extscript.c
index 2d7e0bd80c29e3fa9e625d2e89a41ff665c29794..1d97ac0fc576bb5bafa1adbfdd62c8802565713e 100644 (file)
@@ -111,12 +111,17 @@ CMD_BIND(neonserv_cmd_extscript) {
     }
     command[commandpos] = '\0';
     //we should now have a valid command
-    FILE *fp;
-    fp = popen(command, "r");
-    if (fp) {
-        struct ClientSocket *textbot = getTextBot();
-        pid_t pID = fork();
-        if (pID == 0) { //We're the child process :D
+    struct ClientSocket *textbot = getTextBot();
+       #ifndef WIN32
+    pid_t pID = fork();
+    if (pID == 0) { //We're the child process :D
+        pID = fork();
+        if(pID < 0) exit(EXIT_FAILURE);
+        if(pID != 0) exit(EXIT_SUCCESS);
+       #endif
+        FILE *fp;
+        fp = popen(command, "r");
+        if (fp) {
             char *a;
             while (fgets(command, 1024, fp) != NULL) {
                 if((a = strchr(command, '\n'))) 
@@ -127,17 +132,17 @@ CMD_BIND(neonserv_cmd_extscript) {
                     reply(textbot, user, "%s", command);
             }
             pclose(fp);
-            exit(0);
-        } else if (pID < 0) {
-            reply(getTextBot(), user, "internal bot error - please contact an administrator!");
-            pclose(fp);
         } else {
-            //parent bot - continue program
+            reply(getTextBot(), user, "internal bot error - please contact an administrator!");
         }
-    } else {
-        //error
+       #ifndef WIN32
+        exit(EXIT_FAILURE);
+    } else if (pID < 0) {
         reply(getTextBot(), user, "internal bot error - please contact an administrator!");
-        return;
+    } else {
+        //parent bot - continue program
+        wait(NULL);
     }
+       #endif
 }