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# program.
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, Jan -----Oorspronkelijk bericht----- Van: cygwin-ow...@cygwin.com [mailto:cygwin-ow...@cygwin.com] Namens Jan Alphenaar Verzonden: vrijdag 25 december 2009 22:59 Aan: cygwin@cygwin.com Onderwerp: C / C# combination question Hi everybody, I have just installed the Cygwin environment with Cygwin DLL release version 1.7.1-1. 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, Jan This is my C program: ==== BEGIN C CODE ==== #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <stdbool.h> main() { 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 DataReceivedEventHandler(StdOutputHandler); p.ErrorDataReceived += new DataReceivedEventHandler(StdOutputHandler); p.Start(); p.StandardInput.AutoFlush = true; p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); p.Close(); } private void StdOutputHandler(object sendingProcess, DataReceivedEventArgs Entry) { MessageBox.Show(Entry.Data); } ==== END C# CODE ==== -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple