471,330 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Redirect Cygwin Bash StandardInput, StandardOutput and StandardError

Hi everyone,

this is what I want to do in C#:
1) start a Cygwin Bash Shell
2) send the Shell a command, for example "ls -l"
3) capture all the output of the command

The code below seems to work when I there isn't alot of output to
but when the output increases, the code will freeze.

For example: my "~/tmp" directory contains only 3 files.
Sending the command "ls -l ~/tmp" works as
expected, meaning that I am
able to capture the names of the files in the tmp

my "~/" directory contains 176 files.
Sending the command "ls -l ~" does not work as
expected, meaning that I am
able to capture the names of the first 164 files
after which the code freezes.

Does someone have an idea on what's causing this difference in

thank you,

public static void ExecuteCommand()
Process proc = new Process();
string stOut = "";

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName =
proc.StartInfo.Arguments = "-i -l";


StreamWriter sw = proc.StandardInput;
StreamReader sr = proc.StandardOutput;
StreamReader se = proc.StandardError;

sw.AutoFlush = true;

cmd = "ls -lh";

//if(sr.Peek() >= 0)
Console.WriteLine("sr.Peek = " + sr.Peek());
Console.WriteLine("sr = " + sr.ReadLine());

if(se.Peek() >= 0)
Console.WriteLine("se.Peek = " + se.Peek());
Console.WriteLine("se = " + se.ReadLine());



Dec 19 '05 #1
1 11402

Hi everyone,

it's working ... the problem was apparantly not in my code but
in my development environment.

I just switched my development environment from:
- Microsoft Visual Studio 2003
- version 1.1 of the .NET Framework
- Microsoft Visual Studio 2005
- version 2.0 of the .NET Framework

and now the code works like a charm ...


Panagiotis Arkoudopoulos

Dec 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Zenon | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.