From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11119 invoked by alias); 23 Sep 2009 21:04:37 -0000 Received: (qmail 11109 invoked by uid 22791); 23 Sep 2009 21:04:36 -0000 X-SWARE-Spam-Status: No, hits=0.6 required=5.0 tests=BAYES_50,J_CHICKENPOX_55 X-Spam-Check-By: sourceware.org Received: from chewbacca.tchmachines.com (HELO chewbacca.tchmachines.com) (208.76.82.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 23 Sep 2009 21:04:32 +0000 Received: from bzq-79-181-77-46.red.bezeqint.net ([79.181.77.46] helo=amklaptop) by chewbacca.tchmachines.com with esmtpa (Exim 4.69) (envelope-from ) id 1MqZ0W-000061-Vo for cygwin@cygwin.com; Wed, 23 Sep 2009 17:04:14 -0400 From: "amir knippel" To: Subject: Using bash(cygwin) inside C# program Date: Wed, 23 Sep 2009 21:04:00 -0000 Message-ID: <001e01ca3c91$70f661c0$52e32540$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable x-cr-hashedpuzzle: AXu0 AYSj Ar3k Asby AuMz CcmD Chy9 CmSw CuiU DWJG EB2j FGe9 GucB HANK HhZj HyOy;1;YwB5AGcAdwBpAG4AQABjAHkAZwB3AGkAbgAuAGMAbwBtAA==;Sosha1_v1;7;{4B21EEE3-5422-42D4-B864-F38249D08EEB};YQBtAGkAcgBAAHMAcABpAG4AdQB4AC4AYwBvAG0A;Wed, 23 Sep 2009 21:04:19 GMT;VQBzAGkAbgBnACAAYgBhAHMAaAAoAGMAeQBnAHcAaQBuACkAIABpAG4AcwBpAGQAZQAgAEMAIwAgAHAAcgBvAGcAcgBhAG0A x-cr-puzzleid: {4B21EEE3-5422-42D4-B864-F38249D08EEB} Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2009-09/txt/msg00633.txt.bz2 Hey everyone, i need to use bash shell "inside" C# program. I want to mimic user typing in interactive mode and running cygwin commands. i created a process that runs bash and redirect stdin,stout and std error but I can=92t get tty to work attached is a sample code that starts bash process and redirect the input/output. the problem is that i don't have tty device. if i try to run tty command or stty command i receive error response=20 tty - not a tty=20 stty - Inappropriate ioctl for device i think the this is caused from psi.UseShellExecute =3D false;=20 i need to run cygwin and disable echo with stty -echo but to do this i need a tty device. how can i create a cygwin bash shell with tty device and redirect the stdin, out and error ? Here is simplified code: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; namespace shartCygwin { =A0 =A0 class Program =A0 =A0 { =A0 =A0 =A0 =A0 private static Queue ResponseQueue =3D null; =A0 =A0 =A0 =A0 private static ManualResetEvent ResponseEvent =3D null; =A0 =A0 =A0 =A0 static void Main(string[] args) =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 ResponseQueue =3D new Queue(); =A0 =A0 =A0 =A0 =A0 =A0 ResponseEvent =3D new ManualResetEvent(false); =A0 =A0 =A0 =A0 =A0 =A0 Process bashProcess =3D new Process(); =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.FileName =3D "C:\\cygwin\\bin= \\bash.exe";=20 =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.Arguments =3D "--login -i "; = =A0 =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.WorkingDirectory =3D "C:\\cyg= win\\bin"; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.EnvironmentVariables["CYGWIN"= ] =3D "tty"; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.RedirectStandardError =3D tru= e; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.RedirectStandardInput =3D tru= e; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.RedirectStandardOutput =3D tr= ue; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.CreateNoWindow =3D true; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.UseShellExecute =3D false; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.StartInfo.ErrorDialog =3D false; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.Start(); =A0 =A0 =A0 =A0 =A0 =A0 DataReceivedEventHandler errorEventHandler =3D new DataReceivedEventHandler(ErrorDataReceived); =A0 =A0 =A0 =A0 =A0 =A0 DataReceivedEventHandler outEventHandler =3D new DataReceivedEventHandler(OutDataReceived); =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.OutputDataReceived +=3D outEventHandler; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.ErrorDataReceived +=3D errorEventHandle= r; =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.BeginErrorReadLine(); =A0 =A0 =A0 =A0 =A0 =A0 bashProcess.BeginOutputReadLine(); =A0 =A0 =A0 =A0 =A0 =A0 while(true) =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Thread.Sleep(1000); =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 static void ErrorDataReceived(object sender, DataReceivedEv= entArgs dataReceivedEventArgs) =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 try =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lock (ResponseQueue) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Console.WriteLine(dataReceivedEvent= Args.Data); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ResponseQueue.Enqueue(dataReceivedE= ventArgs.Data); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ResponseEvent.Set(); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 =A0 =A0 catch (Exception e) =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Console.WriteLine(e.Data); =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 static void OutDataReceived(object sender, DataReceivedEven= tArgs dataReceivedEventArgs) =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 try =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lock (ResponseQueue) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Console.WriteLine(dataReceivedEvent= Args.Data); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ResponseQueue.Enqueue(dataReceivedE= ventArgs.Data); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ResponseEvent.Set(); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 =A0 =A0 catch (Exception e) =A0 =A0 =A0 =A0 =A0 =A0 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Console.WriteLine(e.Data); =A0 =A0 =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0 } =A0 =A0 } } -- 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