473,395 Members | 2,796 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,395 software developers and data experts.

redirect standard output size limit

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
4 11894
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jan Gregor | last post by:
Hello I want to redirect output of jython's functions print and println to JTextArea component. Is it possible ? I tried this (swingConsole.textArea is instance): In my class ...
2
by: Grzegorz | last post by:
Hello, I'm using eclipse with pydev plugin, I'm working on a program using wxpython . When I'm executing that application standard error output does not show in eclipse console window - wxpython...
3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
8
by: Peter Ballard | last post by:
Hi all, I've got a C program which outputs all its data using a statement of the form: putchar(ch, outfile); This has worked fine for years until it had to output more than 2GB of data...
14
by: Aaron Couts | last post by:
I have a program that writes to a log file. It's compiled on RH Linux 7.3 (Kernel 2.4.18-18.7). It's using fopen in append mode. When the file reaches 51200000 bytes in size, the program will no...
3
by: Bo | last post by:
In my asp.net webservice application, I need to launch a DOS process as authorized users. To impersonate users, I use <impersonation = true> in my webconfig. I can't use Diagnostics.Process.Start,...
2
by: Brian | last post by:
I'm running a dos program via System.Diagnostics.Process. The dos program is very picky about filenames and such, and so I want to show the output to the user so they can verify it did what it...
9
by: eastcoastguyz | last post by:
I wrote a simple program to continue to create a very large file (on purpose), and even though there is plenty of disk space on that device the program aborted with the error message "File Size...
1
by: TP | last post by:
Hi everybody, I try to find a quick way to redirect the standard output of a Python command (for example: print "message") to a python variable "foobar". Ok, in this simple example, I could do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.