Message-Id: <200912261730.nBQHUuM4004204@delorie.com> X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: Yes, hits=5.5 required=5.0 tests=AWL,BAYES_80,MISSING_MID,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC,TVD_RCVD_IP X-Spam-Check-By: sourceware.org From: "Jan Alphenaar" To: In-Reply-To: Subject: RE: C / C# combination question Date: Sat, 26 Dec 2009 18:30:46 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com] Namens Jan Alphenaar Verzonden: vrijdag 25 december 2009 22:59 Aan: cygwin AT cygwin DOT 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 #include #include #include #include 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