Wolfgang <ratwhs@...> writes:

> 
> Dmitry Chestnykh <dmitry@...> writes:
> 
> > 
> > On Jan 22, 2011, at 2:59 PM, Wolfgang wrote:
> > >> 
> > > I tried Dmitry Chestnykh's solution but i got some trouble, when the 
> > > called
> > > process does subsequent 'system(...)'-calls - new DOS-boxes are flickering
> > > around.
> > 
> > That was because I couldn't make it preserve input/output handles from the
> parent process, 
> > but I'm sure there's a way to do it -- I just don't know how :)
> > 
> > --
> > Dmitry Chestnykh
> > 
> 
> If i change the create flag DETACHED_PROCESS in your code to
> CREATE_NEW_PROCESS_GROUP, your solution works in the same way, as my solution
> with "start /b".
> 
> A ctrl-c kills only the fossil server and the sub process remains actice.
> Closing the DOS box kills the sub process too.
> 
> Wolfgang
> 
Applying the following patch, i got a asynchronous process running, in a way,
that should be compatible with D. Richard Hipp's wishes. I tried it under
Windows XP/Digital Mars C.

After some testing, i have to say, that using start /b doesn't work.
After the sub process exits, a DOS box remains in memory.

Wolfgang

Index: src/main.c
===================================================================
--- src/main.c
+++ src/main.c
@@ -23,11 +23,13 @@
 #include <string.h>
 #include <time.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-
+#if defined _WIN32
+#include <windows.h>
+#endif

 #if INTERFACE

 /*
 ** Number of elements in an array
@@ -428,10 +430,52 @@
   /* On unix, evaluate the command directly.
   */
   rc = system(zOrigCmd);
 #endif
   return rc;
+}
+
+/*
+** This function implements a cross-platform asynchronous "system()" interface.
+** return 0 on success, otherwise -1
+*/
+int fossil_spawn(const char * const zOrigCmd){
+#if defined(_WIN32)
+
+  PROCESS_INFORMATION pi;
+  STARTUPINFO si;
+  BOOL rc;
+  char *zCmd;
+
+  /* copy the command string, CreateProcess may modify the string
+  zCmd := fossil_malloc( strlen(zOrigCmd)*2+2 );
+  strcpy(zCmd,zOrigCmd);
+  memset(&pi, 0, sizeof(pi));
+  memset(&si, 0, sizeof(si));
+  si.cb = sizeof(si);
+  rc = CreateProcess(
+    NULL,                         /* Application Name */
+    zCmd,                         /* Command-line */
+    NULL,                         /* Process attributes */
+    NULL,                         /* Thread attributes */
+    TRUE,                         /* Inherit Handles */
+    CREATE_NEW_PROCESS_GROUP,     /* Create flags  */
+    NULL,                         /* Environment */
+    NULL,                         /* Current directory */
+    &si,                          /* Startup Info */
+    &pi                           /* Process Info */
+ );
+ if( rc ){
+   CloseHandle( pi.hProcess );
+   CloseHandle( pi.hThread );
+ }else{
+   fossil_fatal("cannot create child process: %d", rc);
+ }
+ return 0;
+#else
+  return -1;
+#endif
 }

 /*
 ** Like strcmp() except that it accepts NULL pointers.  NULL sorts before
 ** all non-NULL string pointers.
@@ -1232,10 +1276,15 @@
     iPort = mxPort = atoi(zPort);
   }else{
     iPort = db_get_int("http-port", 8080);
     mxPort = iPort+100;
   }
+
+#if 1
+fossil_spawn("c:\\Programme\\unxtools\\yes g");
+#endif
+
 #if !defined(_WIN32)
   /* Unix implementation */
   if( isUiCmd ){
 #if !defined(__DARWIN__) && !defined(__APPLE__)
     zBrowser = db_get("web-browser", 0);




_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to