redirect standard output size limit

Z

Zenon

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? The pertinent lines are included here:

private ProcessStartInfo compileInfo = new ProcessStartInfo();
private Process compileProcess;

compileInfo.RedirectStandardInput = true;
compileInfo.RedirectStandardOutput = true;
compileInfo.UseShellExecute = false;
compileInfo.CreateNoWindow = true;
compileInfo.FileName = "psftp.exe";
compileInfo.Arguments = userName;
compileProcess = Process.Start(compileInfo);
compileProcess.StandardInput.WriteLine(password);

loggedIn = true;
string tb = "";

if (compileProcess.StandardOutput.ReadLine() != "")
{
tb = compileProcess.StandardOutput.ReadLine();
setTextBoxStatus(tb);
compileProcess.StandardInput.WriteLine("pwd");
tb = compileProcess.StandardOutput.ReadLine();
createTreeViewUX(tb);
}
compileProcess.StandardInput.WriteLine("dir");


char[] endR = new char[1024];

compileProcess.StandardOutput.Read(endR, 0, 1024);
compileProcess.StandardOutput.Read(endR, 0, 1024);

int f = 0;
f = compileProcess.StandardOutput.Peek();
compileProcess.StandardOutput.Read(endRT, 0, 1);


Here is what should be redirected

Listing directory /home/login1
drwx------ 5 login1 users 1024 Feb 7 14:35 .
drwxr-xr-x 15 login2 users 1024 Feb 7 11:01 ..
-rw------- 1 login1 users 0 Feb 6 15:46 .ICEauthority
-rw------- 1 login1 users 73 Feb 6 14:54 .TTauthority
-rw------- 1 login1 users 102 Feb 6 14:54 .Xauthority

.... more files removed for brevity ...

drwxrwxrwx 3 login1 users 96 Feb 16 16:25 tempdir
-rw-r--r-- 1 login1 users 382 Feb 7 11:05 test
psftp>


the first read line, compileProcess.StandardOutput.Read(endR, 0, 1024);
gets the first line "Listing directory /home/login1" fine

the second read gets 1024 chars of the ls command output right up until
about half way through the last line, which is 1024 chars into the
output.

the Peek statement (or read or anything else) fails when I try to look
past this point. Any ideas?

thanks
 
Z

Zenon

Thanks Pete,

I just tried something like the second method in the article (since I
don't know the length) but unfortunately, same problem. As soon as I
try to read the char in position 1024, the application locks up.
Unfortunately, doesn't throw an exception or anything that I could use
to narrow down what's happenning. Any other ideas? I can't figure
this out.

thanks

Z
 
C

Chris Dunaway

You may be hitting a deadlock in your code, especially if you are
redirecting both output and input. Read the remarks in the docs for
the ReDirectStandardOutput property. Part of them is bloew:

The Process component communicates with a child process using a pipe.
If a child process writes enough data to the pipe to fill the buffer,
the child will block until the parent reads the data from the pipe.
This can cause deadlock if your application is reading all output to
standard error and standard output, for example, using the following C#
code.
 
Z

Zenon

That did it, thanks. I had read this documentation before, but did not
completely understand what it meant. Since I wasn't writing to a
console, I didn't know where to write to. You got me thinking about
how to resolve this and I found a flush method which took care of this.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top