* Re: Using bash(cygwin) inside C# program
@ 2009-09-24 10:52 amir knippel
0 siblings, 0 replies; 3+ messages in thread
From: amir knippel @ 2009-09-24 10:52 UTC (permalink / raw)
To: cygwin
References: <4ABA9534.9080203@gmail.com>
> Why exactly do you think you need to run stty and set the tty operating
> parameters, when the bash process is quite plainly *not* connected to a tty,
> it is connected to your C# application?
> It's your application that is in charge of I/O - if it doesn't want echo,
> all it has to do is discard the stuff it reads from the process' stdout
> instead of displaying it, in your OutDataReceived/ErrorDataReceived handlers.
I have code that runs ssh and do some operation on the shell and i want use this code with cygwin.
further more i need operational tty for redirect/input output to /dev/ttyN.
--
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Using bash(cygwin) inside C# program
2009-09-23 21:04 amir knippel
@ 2009-09-23 21:23 ` Dave Korn
0 siblings, 0 replies; 3+ messages in thread
From: Dave Korn @ 2009-09-23 21:23 UTC (permalink / raw)
To: cygwin
amir knippel wrote:
> i created a process that runs bash and redirect stdin,stout and std error
> but I canÂ’t 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
> tty - not a tty
> stty - Inappropriate ioctl for device
> 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 ?
Why exactly do you think you need to run stty and set the tty operating
parameters, when the bash process is quite plainly *not* connected to a tty,
it is connected to your C# application?
It's your application that is in charge of I/O - if it doesn't want echo,
all it has to do is discard the stuff it reads from the process' stdout
instead of displaying it, in your OutDataReceived/ErrorDataReceived handlers.
> bashProcess.StartInfo.EnvironmentVariables["CYGWIN"] = "tty";
Don't do this. Win32 native processes don't understand Cygwin's tty
emulation, which is based on pipes.
cheers,
DaveK
--
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Using bash(cygwin) inside C# program
@ 2009-09-23 21:04 amir knippel
2009-09-23 21:23 ` Dave Korn
0 siblings, 1 reply; 3+ messages in thread
From: amir knippel @ 2009-09-23 21:04 UTC (permalink / raw)
To: cygwin
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 cant 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
tty - not a tty
stty - Inappropriate ioctl for device
i think the this is caused from psi.UseShellExecute = false;
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
{
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);
}
}
}
}
--
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-24 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-24 10:52 Using bash(cygwin) inside C# program amir knippel
-- strict thread matches above, loose matches on Subject: below --
2009-09-23 21:04 amir knippel
2009-09-23 21:23 ` Dave Korn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).