473,225 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 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
capture,
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
directory.

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
behaviour?

thank you,

Gioti
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 =
"j:/cygwin/cygwin-1.5.18-1-3/bin/bash.exe"";
proc.StartInfo.Arguments = "-i -l";

proc.Start();

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

sw.AutoFlush = true;

cmd = "ls -lh";
sw.WriteLine(cmd);

while(true)
{
//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());
}
}

sw.Close();
sr.Close();

proc.WaitForExit();
proc.Close();
}

Dec 19 '05 #1
1 11599

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
to:
- Microsoft Visual Studio 2005
- version 2.0 of the .NET Framework

and now the code works like a charm ...

cu,

Panagiotis Arkoudopoulos

Dec 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Woudenberg | last post by:
I just installed a Python 2.3.4 Windows binary on a friend's WinXP machine (because the latest Cygwin-provided Python 2.3 build leaves out the winsound module for some reason). When I try and...
0
by: John Lewin | last post by:
I've recently discovered the value of using existing console applications in managed .net apps. Unfortunately, I've stumbled into a problem with a particular console application that check's crc...
2
by: mwazir | last post by:
Hi all, I have reposted this question from dotnet.general as I have been advised that this is a more appropriate forum for this question. Apologies for the repost. I have a process thats...
2
by: Ivan Lam | last post by:
Hi all, Thanks for reading my post!!! I am facing a problem that I cannot redirect StandartOutput and StandardInput at the same time without closing the executive. Actually, I have a...
4
by: Zenon | last post by:
I have a C# application which interacts with an HP UNIX box via PSFTP. I have run in to a problem where the maximum amount of characters I can redirect is 1024. This number leads me to believe...
0
by: Andrew | last post by:
Hello, My question is this: You have an application(parent) which creates a child process and redirects its StandardOutput and StandardError To avoid deadlock 2 threads are used to read from...
0
by: shravagiparag | last post by:
Hello, I am developing a console application to invoke gdb session and log in the communication between my application and gdb. I opened gdb as a new process and tried to redirect the input and...
0
by: dot | last post by:
I spent a few headache filled days trying to use GMP on windows (XP pro) I finally got it to work and since I found little help on the Web I thought someone might find what i did useful. ...
1
by: Dv | last post by:
When our application is launched from Dos console, we need to print some message to the console. I attached our application to the console using AttachConsole(ATTACH_PARENT_PROCESS), and then call...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.