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 ProcessStartInf o compileInfo = new ProcessStartInf o();
private Process compileProcess;
compileInfo.Red irectStandardIn put = true;
compileInfo.Red irectStandardOu tput = true;
compileInfo.Use ShellExecute = false;
compileInfo.Cre ateNoWindow = true;
compileInfo.Fil eName = "psftp.exe" ;
compileInfo.Arg uments = userName;
compileProcess = Process.Start(c ompileInfo);
compileProcess. StandardInput.W riteLine(passwo rd);
loggedIn = true;
string tb = "";
if (compileProcess .StandardOutput .ReadLine() != "")
{
tb = compileProcess. StandardOutput. ReadLine();
setTextBoxStatu s(tb);
compileProcess. StandardInput.W riteLine("pwd") ;
tb = compileProcess. StandardOutput. ReadLine();
createTreeViewU X(tb);
}
compileProcess. StandardInput.W riteLine("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 4 11963
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.goo glegroups.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 ProcessStartInf o compileInfo = new ProcessStartInf o(); private Process compileProcess;
compileInfo.Red irectStandardIn put = true; compileInfo.Red irectStandardOu tput = true; compileInfo.Use ShellExecute = false; compileInfo.Cre ateNoWindow = true; compileInfo.Fil eName = "psftp.exe" ; compileInfo.Arg uments = userName; compileProcess = Process.Start(c ompileInfo); compileProcess. StandardInput.W riteLine(passwo rd);
loggedIn = true; string tb = "";
if (compileProcess .StandardOutput .ReadLine() != "") { tb = compileProcess. StandardOutput. ReadLine(); setTextBoxStatu s(tb); compileProcess. StandardInput.W riteLine("pwd") ; tb = compileProcess. StandardOutput. ReadLine(); createTreeViewU X(tb); } compileProcess. StandardInput.W riteLine("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
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
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 ReDirectStandar dOutput 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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
self.printStream= MyPrintStream(System.out)
|
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 seems to redirect standard output to some
another window , and closes that window immediately, so I can't see any
error messagess.
Is there a way to redirect standard output to eclipse console ?
|
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. The obvious way to do this is
by using the static Console type properties, In and Out. When trying to
debug the app in the IDE however, this doesn't appear to work. I've edited
the project properties and added the necessary text to the "command...
|
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 today, and I got a "file size limit exceeded" error.
|
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 longer write to the file. When
this happens, fopen and fputs do not return an error. I've been researching
large file support for Linux, and it all has to do with the regular 2-gig file
size limit. If it's something obvious, sorry -- I'm a C...
| |
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, because
it creates a child process using parent process token "System", not
the impersonated thread token. I don't want to use
CreateProcessWithLogonW, because my application impersonates different
users and it is not a good idea to handle...
|
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 was supposed
to do.
When I create my process like this it doesn't redirect the standard output:
Process prcs = new Process();
prcs.StartInfo.UseShellExecute = false;
|
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 Limit Exceeded".
The file size was 2147483647. I checked ulimit -a and its set to
unlimited.
Is this a compiler issue? I would like to see a C code example of how
to increase the limit or make it unlimited (if that is a wise thing to
do).
|
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 foobar = "message", but in
fact 'print "message"' could be replaced by any Python function writing on
standard output.
I have googled on this subject.
To redirect to a variable, I could use a temporary file:
|
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...
|
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,...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |