This is the mail archive of the cygwin 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]
Other format: [Raw text]

RE: C / C# combination question

Hi again,

After some more extensive debugging I was able to find out what goes wrong
with an environment variable if a Cygwin C program is called from a C#

If an environment variable is in uppercase (like in my code) the getenv call
in the C program will not be able to find it.

On the other hand, if the environment variable is in lower case in both
programs, the getenv call is able to find it. So, there must be some kind of
upper to lowercase translation on the way.

Anyway, it works for me now.

Warm regards,


-----Oorspronkelijk bericht-----
Van: [] Namens Jan
Verzonden: vrijdag 25 december 2009 22:59
Onderwerp: C / C# combination question

Hi everybody,

I have just installed the Cygwin environment with Cygwin DLL release version

My goal is to call a Cygwin compiled C program from a C# program written in
Visual studio 2008 and read an environment variable from the Windows
environment in the C program.

Unfortunately my C program is not able to read the environment variable set
in the C# program.

For the purpose of elimination here are some facts:

1) If I replace the C program for a windows .bat file and call this .bat
file from the C# program it returns the environment variable.
2) Calling the C program directly in a dos box, results in the fact that it
can read an environment variable.
3) In previous versions of cygwin, this worked correctly, although I am not
sure with which version of the Cygwin DLL release.

Has anybody seen this rather strange behaviour before ?

Any help is greatly appreciated.

Warm regards,


This is my C program:

==== BEGIN C CODE ====
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>

   printf("%s\n", getenv("CYGWIN"));
==== END C CODE ====

And this is my C# code:
==== BEGIN C# CODE ====
        private void button1_Click(object sender, EventArgs e)
            Process p = new Process();

            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.FileName = @"D:\Test\bin\jan.exe";

            p.StartInfo.EnvironmentVariables["CYGWIN"] = "nodosfilewarning";

            p.OutputDataReceived += new
            p.ErrorDataReceived += new


            p.StandardInput.AutoFlush = true;




        private void StdOutputHandler(object sendingProcess,
DataReceivedEventArgs Entry)
==== END C# CODE ====

Problem reports:
Unsubscribe info:

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