Message-Id: <200912252158.nBPLwhTD015156@delorie.com> X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=4.5 required=5.0 tests=AWL,BAYES_40,MISSING_MID,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC,TVD_RCVD_IP X-Spam-Check-By: sourceware.org From: "Jan Alphenaar" To: Subject: C / C# combination question Date: Fri, 25 Dec 2009 22:58:34 +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 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