delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/11/07/16:24:16

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Wed, 7 Nov 2001 16:50:08 +0100
From: "Gerrit P. Haase" <gerrit AT familiehaase DOT de>
X-Mailer: The Bat! (v1.53t) UNREG / CD5BF9353B3B7091
Reply-To: "Gerrit P. Haase" <cygwin AT cygwin DOT com>
Organization: convey Information Systems GmbH
X-Priority: 3 (Normal)
Message-ID: <8969183270.20011107165008@familiehaase.de>
To: Heiko_Elger AT arburg DOT com
CC: cygwin AT cygwin DOT com
Subject: Re: 1.3.4: error in inheriting new PATH environment form WIN32 executable to CYGWIN executable
In-Reply-To: <OF4C6A95E3.F945D816-ONC1256AFD.0048D132@lossburg.arburg.com>
References: <OF4C6A95E3 DOT F945D816-ONC1256AFD DOT 0048D132 AT lossburg DOT arburg DOT com>
MIME-Version: 1.0
X-Hops: 1
X-Sender: 320081107336-0001 AT t-dialin DOT net

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 DOT haase AT convey DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019