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