By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,644 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,644 IT Pros & Developers. It's quick & easy.

redirect standard output size limit

P: n/a
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

Feb 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jon Skeet has an article on reading from streams. It's targetted towards
binary data, but I think it applies to this case:
http://www.yoda.arachsys.com/csharp/readbinary.html

Pete

"Zenon" <ze****@comcast.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

Feb 21 '06 #2

P: n/a
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

Feb 21 '06 #3

P: n/a
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.

Feb 21 '06 #4

P: n/a
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.

Feb 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.