473,806 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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. RedirectStandar dInput = true;
proc.StartInfo. RedirectStandar dOutput = true;
proc.StartInfo. RedirectStandar dError = 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.StandardIn put;
StreamReader sr = proc.StandardOu tput;
StreamReader se = proc.StandardEr ror;

sw.AutoFlush = true;

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

while(true)
{
//if(sr.Peek() >= 0)
{
Console.WriteLi ne("sr.Peek = " + sr.Peek());
Console.WriteLi ne("sr = " + sr.ReadLine());
}

if(se.Peek() >= 0)
{
Console.WriteLi ne("se.Peek = " + se.Peek());
Console.WriteLi ne("se = " + se.ReadLine());
}
}

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

proc.WaitForExi t();
proc.Close();
}

Dec 19 '05 #1
1 11639

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
2986
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 run this newly installed Python from bash it just hangs (no version message, no prompt, CPU is idle). When I run it from IDLE, or the DOS CMD prompt, it runs fine. Also, Python scripts using the new version run fine, even invoked on the bash command...
0
412
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 info on CDs. Using either the StandardError or StandardOutput streams read, readline or peek methods causes an immediate block that doesn't release until the console app finishes it's business. I want to launch this console app and update my UI to...
2
2264
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 starts in my application and only terminates when my application is terminated. I want to write the output and the errors of this process to a seperate log file. In order to do this, I spawned two threads.
2
3186
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 console application named "etm.exe", I would like to call it in my .net (VC) application. What I want to do is when the user type some command in my .net application, I redirect this command
4
12012
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 that it is not random and perhaps there is some flushing that needs to occur before I can read more. I couldn't find anything about the 1024 char limit anywhere. Is anyone familiar with such a thing, or am I just doing something wrong in my code? ...
0
1138
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 the child process, each thread reading a stream. Is it thread safe to use the Process object and read the 2 streams ? if yes can you please say why ?
0
1910
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 output of the process to a streamwriter.But its not working. I am able to redirect the standard input for the gdb process i.e. I can issue commands from my application to gdb but I am not able to redirect its standard output. The gdb process does...
0
3314
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. Creating an environment suitable for GMP programming. 1) Create 'cygwin' environment (see below) 2)add GMP to the cygwin directory (see below)
1
2493
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 Console.WriteLine(...) to print some messages there. Everything works fine, except that after the message has been printed, it'll require user to press any key exit from there. So, I'd like to insert a key stroke to the StandardInput...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.