necesito usar el programa C# dentro del programa "bash shell". Quiero imitar el tipeo del usuario en modo interactivo y ejecutar comandos de cygwin.Usando bash (cygwin) dentro del programa C#
creé un proceso que ejecuta bash y redirigir stdin, stout y std error pero no puedo obtener tty para trabajar adjunto es un código de muestra que inicia el proceso bash y redirige la entrada/salida.
el problema es que no tengo dispositivo tty. Si trato de ejecutar comandos TTY o un comando stty recibo una respuesta de error
tty - not a tty
stty - Inappropriate ioctl for device
creo que el presente es causado por psi.UseShellExecute = false;
necesito para ejecutar cygwin y desactivar eco con stty -echo pero para hacer esto i necesita un dispositivo tty. ¿Cómo puedo crear un shell cygwin bash con dispositivo tty y redirigir el stdin, out y error?
1) ¿Qué es lo que falta?
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
namespace shartCygwin
{
class Program
{
private static Queue<string> ResponseQueue = null;
private static ManualResetEvent ResponseEvent = null;
static void Main(string[] args)
{
ResponseQueue = new Queue<string>();
ResponseEvent = new ManualResetEvent(false);
Process bashProcess = new Process();
bashProcess.StartInfo.FileName = "C:\\cygwin\\bin\\bash.exe";
bashProcess.StartInfo.Arguments = "--login -i ";
bashProcess.StartInfo.WorkingDirectory = "C:\\cygwin\\bin";
bashProcess.StartInfo.EnvironmentVariables["CYGWIN"] = "tty";
bashProcess.StartInfo.RedirectStandardError = true;
bashProcess.StartInfo.RedirectStandardInput = true;
bashProcess.StartInfo.RedirectStandardOutput = true;
bashProcess.StartInfo.CreateNoWindow = true;
bashProcess.StartInfo.UseShellExecute = false;
bashProcess.StartInfo.ErrorDialog = false;
bashProcess.Start();
DataReceivedEventHandler errorEventHandler = new DataReceivedEventHandler(ErrorDataReceived);
DataReceivedEventHandler outEventHandler = new DataReceivedEventHandler(OutDataReceived);
bashProcess.OutputDataReceived += outEventHandler;
bashProcess.ErrorDataReceived += errorEventHandler;
bashProcess.BeginErrorReadLine();
bashProcess.BeginOutputReadLine();
while(true)
{
Thread.Sleep(1000);
}
}
static void ErrorDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
{
try
{
lock (ResponseQueue)
{
Console.WriteLine(dataReceivedEventArgs.Data);
ResponseQueue.Enqueue(dataReceivedEventArgs.Data);
ResponseEvent.Set();
}
}
catch (Exception e)
{
Console.WriteLine(e.Data);
}
}
static void OutDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
{
try
{
lock (ResponseQueue)
{
Console.WriteLine(dataReceivedEventArgs.Data);
ResponseQueue.Enqueue(dataReceivedEventArgs.Data);
ResponseEvent.Set();
}
}
catch (Exception e)
{
Console.WriteLine(e.Data);
}
}
}
}
Ejecuté su programa, y aunque veo el error "Ioctl inapropiado para el dispositivo", también veo el aviso de cygwin bash después de eso. ¿Cuál es exactamente el problema? Quité la línea CYGWIN = tty y veo que la salida de TE es en bruto, con los códigos de control que se muestran. –
@Hemlock - Creo que la clave aquí, basada en la respuesta de Kevin Mark, es que tienes que decidir si usar o no el eco, entonces realmente importa si desactivas el eco/etc ... Y qué motivación hay ¿Por intentar engañar a CYGWIN para que use un TTY? – Peter