P
Panagiotis
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();
}
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();
}