On 5/11/2005 9:53 AM, Christopher Faylor wrote:
On Wed, May 11, 2005 at 11:40:36AM -0400, Christopher Faylor wrote:

It sounds like you need to read MSDN on CreateProcess and see what it says
about "lpEnvironment":

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp

cygstart uses ShellExecute, not CreateProcess.

Btw, from the description, it sounds like cygstart is broken right now
and could be fixed right now.  You don't need any of the functionality
from the snapshot.  You just need to construct a windows lpEnvironment
block from the UNIX-like global variable, provided by cygwin: "extern char 
**environ".

The attached patch fixes cygstart for me. It copies all missing Cygwin environment variables to the Windows environment before invoking ShellExecute.


--
David Rothenberger                spammer? -> [EMAIL PROTECTED]
GPG/PGP: 0x7F67E734, C233 365A 25EF 2C5F C8E1 43DF B44F BA26 7F67 E734

It'll be a nice world if they ever get it finished.
--- cygutils-1.2.7-orig/src/cygstart/cygstart.c 2005-03-07 21:22:51.000000000 
-0800
+++ cygutils-1.2.7/src/cygstart/cygstart.c      2005-05-11 11:43:55.598000000 
-0700
@@ -24,6 +24,7 @@
 #include "config.h"
 #endif
 #include "common.h"
+#include <sys/cygwin.h>
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "cygstart"
@@ -64,6 +65,7 @@
 static void help(poptContext optCon, FILE *f, char *name);
 static void version(poptContext optCon, FILE *f, char *name);
 static void license(poptContext optCon, FILE *f, char *name);
+static void setup_win_environ(void);
 
 int main(int argc, const char **argv)
 {
@@ -404,6 +406,7 @@
 {
     int ret;
 
+    setup_win_environ();
     ret = (int) ShellExecute(NULL, action, aPath, args, workDir, show);
     if (ret >= 32) {
         return TRUE;
@@ -511,3 +514,23 @@
   printTopDescription(f, name);
   printLicense(f, name);
 }  
+
+/* Copy cygwin environment variables to the Windows environment if they're not 
already there. */
+static void setup_win_environ(void)
+{
+    char **envp = (char **) cygwin_internal (CW_ENVP);
+    char *var, *val;
+    char curval[2];
+
+    while (envp && *envp) {
+        var = strdup(*envp++);
+        val = strchr(var, '=');
+        *val++ = '\0';
+        
+        if (GetEnvironmentVariable(var, curval, 2) == 0 && GetLastError() == 
ERROR_ENVVAR_NOT_FOUND) {
+            SetEnvironmentVariable(var, val);
+        }
+
+        free(var);
+    }
+}

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to