This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 1.3.4: error in inheriting new PATH environment form WIN32 executable to CYGWIN executable


Hallo Heiko,

2001-11-07 16:10:14, du schriebst:

> If a MS WIN 32 program changes his environment PATH variable to a very long
> value (over 270 characters) and than calling a CYGWIN program per system() call
> the path inside the CYGWIN program is reset to NULL! If it calls a MS WIN 32
> program all works fine.

> We have this problem with clearmake in exporting a very long path and the shell
> is the CYGWIN sh.exe.

> I tried to reproduce it within a very small test.
> I wrote two small programs (belwo you wil find the sourcecode):
>    changeenv.c --> MS WIN 32 program which change his PATH environment and calls
> per system() the program "printpath"
>    printpath.c   --> prints the PATH environment to stdout

> changeenv.exe is compiled with Microsoft Visual Studio.
> printpath.exe is compiled with MS Visual Studio and cygwin gcc

> I hope anyone can reproduce this error and give me a hint to resolve may
> problem.

Yes, I used borland cc, there it is also not ok.  Why not use gcc?

At first I have modified the sources a little:

> ----------------------- start changeenv.c --------------------
#include <stdio.h>
#include <stdlib.h>

#define CYGWIN_SHELL        "c:/cygwin/bin/sh"
#define CYGWIN_PRINTPATH    "c:/cygwin/home/Gerrit/script/printpath_gcc"
#define WIN32_PRINTPATH     "c:/cygwin/home/Gerrit/script/printpath_bcc"

char long_path[] = "PATH=/usr/bin:/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";

int main (int argc, char ** argv, char **env)
{
    int rc=0;
    char * env_path ;

    if (putenv(long_path) == -1)
        perror("putenv()");

    env_path = getenv("PATH");
    printf("NEW PATH=\n%s\n", env_path == NULL ? "" : env_path);
    if (system( CYGWIN_SHELL " -ic \"echo system CYGWIN SHELL PATH=\"") != 0)
        perror("system()");
    if (system( CYGWIN_SHELL " -ic \"echo $PATH\"") != 0)
        perror("system()");
    printf("system CYGWIN printpath: "); fflush( stdout );
    if (system( CYGWIN_PRINTPATH ) != 0)
        perror("system()");
    printf("system WIN32 printpath: "); fflush( stdout );
    if (system( WIN32_PRINTPATH ) != 0)
        perror("system()");

    return rc;
}
> ----------------------- end changeenv.c --------------------

> ----------------------- start printpath.c --------------------
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char ** argv, char **env)
{
    int rc=0;
    char * env_path ;

    env_path = getenv("PATH");
    printf("PATH=\n%s\n", env_path == NULL ? "" : env_path);

    return rc;
}
> }----------------------- end printpath.c --------------------


Well, compiled with borland cc I get this (same as you):

$ ./changeenv_bcc
NEW PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
system CYGWIN SHELL PATH=
system CYGWIN printpath: PATH=

system WIN32 printpath: PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890

And it is o.k. if compiled with gcc:

$ ./changeenv_gcc
NEW PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
system CYGWIN SHELL PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
system CYGWIN printpath: PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
system WIN32 printpath: PATH=
C:\cygwin\bin;C:\cygwin\123456789012345678901234567890123456789012345678901234567890123456
789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
7890C:\
  ^^^^^^ Don't know where this came from...

It works o.k, even if I make the NEW PATH longer (say twice of your version) but
only if compiled with gcc.
Seems to be a limit in bcc (or vcc for you).

$ ./changeenv_gcc
NEW PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890/123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890
system CYGWIN SHELL PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890/123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890
system CYGWIN printpath: PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890/123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890
system WIN32 printpath: PATH=
C:\cygwin\bin;

$ ./changeenv_bcc
NEW PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890/123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890
system CYGWIN SHELL PATH=

system CYGWIN printpath: PATH=

system WIN32 printpath: PATH=
/usr/bin:/12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890/123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890

Maybe you can use gcc, it looks like it is much better for those kind of jobs;)

Gerrit
-- 
convey Information Systems GmbH                   http://www.convey.de/
                                                  Vitalisstraße 326-328
Gerrit P. Haase                                   D-50933 Köln
gerrit.haase@convey.de                            Fon: ++49 221 6903922


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]