]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/cmdlib/cmdlib.cpp
automatically run the decompiler when specifying a BSP file in Import...
[xonotic/netradiant.git] / libs / cmdlib / cmdlib.cpp
index a09ed9ead1a39e9106e08a534d85b0bde7c2fea5..f6ace0fe117f3424ae6d4108d83840f73b88cef1 100644 (file)
@@ -36,16 +36,23 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #if defined (POSIX)
 
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
-bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
+bool Q_Exec(const char *cmd, char *cmdline, const char *, bool, bool waitfor)
 {
   char fullcmd[2048];
   char *pCmd;
+  pid_t pid;
 #ifdef _DEBUG
   printf("Q_Exec damnit\n");
 #endif
-  switch (fork())
+  switch ((pid = fork()))
   {
+  default:
+    if(waitfor)
+      waitpid(pid, NULL, 0);
+    break;
   case -1:
     return true;
     break;
@@ -84,7 +91,7 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
 #include <windows.h>
 
 // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
-bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole)
+bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor)
 {
   PROCESS_INFORMATION ProcessInformation;
   STARTUPINFO startupinfo = {0};
@@ -121,7 +128,11 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateCon
                     &startupinfo,
                     &ProcessInformation
                     ))
+  {
+    if(waitfor)
+      WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
     return true;
+  }
   return false;
 }