473,396 Members | 1,810 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,396 software developers and data experts.

Redirecting StandardOutput

I'm having a problem with redirecting the StandardOutput of a process that I
use to run a DOS program in my application. The problem is that I when I
start my process (which I do in a separate thread) I can't read anything
from the stdout before the process actually finishes. If I do something like
this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process
has finished. This is a problem because the program I am running transfers
files to a server and can take a long time to finish, but I'm unable to give
the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things
up until the process has finished? I can't believe there isn't a way to do
this!!

Cheers
Nov 15 '05 #1
15 3055
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
I'm having a problem with redirecting the StandardOutput of a process that I
use to run a DOS program in my application. The problem is that I when I
start my process (which I do in a separate thread) I can't read anything
from the stdout before the process actually finishes. If I do something like
this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process
has finished. This is a problem because the program I am running transfers
files to a server and can take a long time to finish, but I'm unable to give
the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things
up until the process has finished? I can't believe there isn't a way to do
this!!


I haven't seen this problem - is the standard output (not standard
error) definitely writing whole lines of text? Could you give a short
but complete example? (I remember writing a small "echo" program a
while ago which showed standard input and standard output working, for
example.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
I'm having a problem with redirecting the StandardOutput of a process that I
use to run a DOS program in my application. The problem is that I when I
start my process (which I do in a separate thread) I can't read anything
from the stdout before the process actually finishes. If I do something like
this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process
has finished. This is a problem because the program I am running transfers
files to a server and can take a long time to finish, but I'm unable to give
the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things
up until the process has finished? I can't believe there isn't a way to do
this!!


I haven't seen this problem - is the standard output (not standard
error) definitely writing whole lines of text? Could you give a short
but complete example? (I remember writing a small "echo" program a
while ago which showed standard input and standard output working, for
example.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Okay, thanks for your response, here is a short test app I wrote that shows
the same behavior as the app I'm trying to write. The process I'm trying to
run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)

using System;

using System.Diagnostics;

using System.Threading;

using System.IO;

namespace ProcessTest

{

class Class1

{

public string m_ProcessArgs;

public string m_ProcessApp;

public string m_Password;

public string m_UserID;

public string m_Address;

public string m_CalcPath;

public Process m_Running;

public StreamReader m_StdOut;

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

Class1 myClass = new Class1();

myClass.m_UserID = "*******";

myClass.m_Address = "********"; // address of server

myClass.m_CalcPath = "/*********/"; // path on server

myClass.m_Password = "******";

myClass.PutFiles(@"C:\Data");

// ******* removed for security reasons!!

Console.ReadLine();

}

public void PutFiles(string FilePath)

{

m_ProcessArgs = "-r -pw " + m_Password + " " + FilePath + " " + m_UserID +
"@" + m_Address + ":" + m_CalcPath;

m_ProcessApp = "pscp.exe";

Console.WriteLine("Starting transfer thread");

Thread myThread = new Thread(new ThreadStart(TransferProcess));

myThread.Start();

Console.WriteLine("The transfer thread has been started");

}

private void TransferProcess()

{

ProcessStartInfo pInfo = new ProcessStartInfo(m_ProcessApp,m_ProcessArgs);

pInfo.UseShellExecute = false;

pInfo.RedirectStandardOutput = true;

pInfo.RedirectStandardError = true;

pInfo.CreateNoWindow = true;

m_Running = new Process();

m_Running.StartInfo = pInfo;

Console.WriteLine("TransferProcess is starting process....");

m_Running.Start();

// This line appears immediately

Console.WriteLine("The Process has started");

m_StdOut = m_Running.StandardOutput;

// This line doesn't appear until the process has completed

Console.WriteLine("This was read from the StdOut: " + m_StdOut.Read());

m_Running.WaitForExit();

// This appears immediately after the last line, indicating that the last
line wasn't displayed

// until the end of the process

Console.WriteLine("File Transfer Done");

Console.ReadLine();

}

}

}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I
start my process (which I do in a separate thread) I can't read anything
from the stdout before the process actually finishes. If I do something like this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process has finished. This is a problem because the program I am running transfers files to a server and can take a long time to finish, but I'm unable to give the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things up until the process has finished? I can't believe there isn't a way to do this!!


I haven't seen this problem - is the standard output (not standard
error) definitely writing whole lines of text? Could you give a short
but complete example? (I remember writing a small "echo" program a
while ago which showed standard input and standard output working, for
example.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4
Okay, thanks for your response, here is a short test app I wrote that shows
the same behavior as the app I'm trying to write. The process I'm trying to
run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)

using System;

using System.Diagnostics;

using System.Threading;

using System.IO;

namespace ProcessTest

{

class Class1

{

public string m_ProcessArgs;

public string m_ProcessApp;

public string m_Password;

public string m_UserID;

public string m_Address;

public string m_CalcPath;

public Process m_Running;

public StreamReader m_StdOut;

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

Class1 myClass = new Class1();

myClass.m_UserID = "*******";

myClass.m_Address = "********"; // address of server

myClass.m_CalcPath = "/*********/"; // path on server

myClass.m_Password = "******";

myClass.PutFiles(@"C:\Data");

// ******* removed for security reasons!!

Console.ReadLine();

}

public void PutFiles(string FilePath)

{

m_ProcessArgs = "-r -pw " + m_Password + " " + FilePath + " " + m_UserID +
"@" + m_Address + ":" + m_CalcPath;

m_ProcessApp = "pscp.exe";

Console.WriteLine("Starting transfer thread");

Thread myThread = new Thread(new ThreadStart(TransferProcess));

myThread.Start();

Console.WriteLine("The transfer thread has been started");

}

private void TransferProcess()

{

ProcessStartInfo pInfo = new ProcessStartInfo(m_ProcessApp,m_ProcessArgs);

pInfo.UseShellExecute = false;

pInfo.RedirectStandardOutput = true;

pInfo.RedirectStandardError = true;

pInfo.CreateNoWindow = true;

m_Running = new Process();

m_Running.StartInfo = pInfo;

Console.WriteLine("TransferProcess is starting process....");

m_Running.Start();

// This line appears immediately

Console.WriteLine("The Process has started");

m_StdOut = m_Running.StandardOutput;

// This line doesn't appear until the process has completed

Console.WriteLine("This was read from the StdOut: " + m_StdOut.Read());

m_Running.WaitForExit();

// This appears immediately after the last line, indicating that the last
line wasn't displayed

// until the end of the process

Console.WriteLine("File Transfer Done");

Console.ReadLine();

}

}

}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I
start my process (which I do in a separate thread) I can't read anything
from the stdout before the process actually finishes. If I do something like this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process has finished. This is a problem because the program I am running transfers files to a server and can take a long time to finish, but I'm unable to give the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things up until the process has finished? I can't believe there isn't a way to do this!!


I haven't seen this problem - is the standard output (not standard
error) definitely writing whole lines of text? Could you give a short
but complete example? (I remember writing a small "echo" program a
while ago which showed standard input and standard output working, for
example.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
ewww, hungarian notation...

" Matt Burland" <wjousts@[nospam]hotmail.com> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
Okay, thanks for your response, here is a short test app I wrote that shows the same behavior as the app I'm trying to write. The process I'm trying to run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)

using System;

using System.Diagnostics;

using System.Threading;

using System.IO;

namespace ProcessTest

{

class Class1

{

public string m_ProcessArgs;

public string m_ProcessApp;

public string m_Password;

public string m_UserID;

public string m_Address;

public string m_CalcPath;

public Process m_Running;

public StreamReader m_StdOut;

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

Class1 myClass = new Class1();

myClass.m_UserID = "*******";

myClass.m_Address = "********"; // address of server

myClass.m_CalcPath = "/*********/"; // path on server

myClass.m_Password = "******";

myClass.PutFiles(@"C:\Data");

// ******* removed for security reasons!!

Console.ReadLine();

}

public void PutFiles(string FilePath)

{

m_ProcessArgs = "-r -pw " + m_Password + " " + FilePath + " " + m_UserID +
"@" + m_Address + ":" + m_CalcPath;

m_ProcessApp = "pscp.exe";

Console.WriteLine("Starting transfer thread");

Thread myThread = new Thread(new ThreadStart(TransferProcess));

myThread.Start();

Console.WriteLine("The transfer thread has been started");

}

private void TransferProcess()

{

ProcessStartInfo pInfo = new ProcessStartInfo(m_ProcessApp,m_ProcessArgs);

pInfo.UseShellExecute = false;

pInfo.RedirectStandardOutput = true;

pInfo.RedirectStandardError = true;

pInfo.CreateNoWindow = true;

m_Running = new Process();

m_Running.StartInfo = pInfo;

Console.WriteLine("TransferProcess is starting process....");

m_Running.Start();

// This line appears immediately

Console.WriteLine("The Process has started");

m_StdOut = m_Running.StandardOutput;

// This line doesn't appear until the process has completed

Console.WriteLine("This was read from the StdOut: " + m_StdOut.Read());

m_Running.WaitForExit();

// This appears immediately after the last line, indicating that the last
line wasn't displayed

// until the end of the process

Console.WriteLine("File Transfer Done");

Console.ReadLine();

}

}

}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I start my process (which I do in a separate thread) I can't read anything from the stdout before the process actually finishes. If I do
something
like this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process has finished. This is a problem because the program I am running transfers files to a server and can take a long time to finish, but I'm unable
to
give the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things up until the process has finished? I can't believe there isn't a way
to
do this!!


I haven't seen this problem - is the standard output (not standard
error) definitely writing whole lines of text? Could you give a short
but complete example? (I remember writing a small "echo" program a
while ago which showed standard input and standard output working, for
example.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #6
ewww, hungarian notation...

" Matt Burland" <wjousts@[nospam]hotmail.com> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
Okay, thanks for your response, here is a short test app I wrote that shows the same behavior as the app I'm trying to write. The process I'm trying to run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)

using System;

using System.Diagnostics;

using System.Threading;

using System.IO;

namespace ProcessTest

{

class Class1

{

public string m_ProcessArgs;

public string m_ProcessApp;

public string m_Password;

public string m_UserID;

public string m_Address;

public string m_CalcPath;

public Process m_Running;

public StreamReader m_StdOut;

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

Class1 myClass = new Class1();

myClass.m_UserID = "*******";

myClass.m_Address = "********"; // address of server

myClass.m_CalcPath = "/*********/"; // path on server

myClass.m_Password = "******";

myClass.PutFiles(@"C:\Data");

// ******* removed for security reasons!!

Console.ReadLine();

}

public void PutFiles(string FilePath)

{

m_ProcessArgs = "-r -pw " + m_Password + " " + FilePath + " " + m_UserID +
"@" + m_Address + ":" + m_CalcPath;

m_ProcessApp = "pscp.exe";

Console.WriteLine("Starting transfer thread");

Thread myThread = new Thread(new ThreadStart(TransferProcess));

myThread.Start();

Console.WriteLine("The transfer thread has been started");

}

private void TransferProcess()

{

ProcessStartInfo pInfo = new ProcessStartInfo(m_ProcessApp,m_ProcessArgs);

pInfo.UseShellExecute = false;

pInfo.RedirectStandardOutput = true;

pInfo.RedirectStandardError = true;

pInfo.CreateNoWindow = true;

m_Running = new Process();

m_Running.StartInfo = pInfo;

Console.WriteLine("TransferProcess is starting process....");

m_Running.Start();

// This line appears immediately

Console.WriteLine("The Process has started");

m_StdOut = m_Running.StandardOutput;

// This line doesn't appear until the process has completed

Console.WriteLine("This was read from the StdOut: " + m_StdOut.Read());

m_Running.WaitForExit();

// This appears immediately after the last line, indicating that the last
line wasn't displayed

// until the end of the process

Console.WriteLine("File Transfer Done");

Console.ReadLine();

}

}

}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I start my process (which I do in a separate thread) I can't read anything from the stdout before the process actually finishes. If I do
something
like this:

Process myProcess = new Process(myStartInfo)
// this gets shown straight away
MessageBox.Show("Process Started");
string s = myProcess.StandardOutput.Readline();
// this doesn't get shown until the process has finished
MessageBox.Show(s);
myProcess.WaitForExit();
// this gets shown immediately following the last MessageBox
MessageBox.Show("Process Finished");

It's clear that I'm not reading anything from the stdout before the process has finished. This is a problem because the program I am running transfers files to a server and can take a long time to finish, but I'm unable
to
give the user any information about what is going on during the transfer.
Can somebody please tell me how to read the stdout without hanging up things up until the process has finished? I can't believe there isn't a way
to
do this!!


I haven't seen this problem - is the standard output (not standard
error) definitely writing whole lines of text? Could you give a short
but complete example? (I remember writing a small "echo" program a
while ago which showed standard input and standard output working, for
example.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #7
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
Okay, thanks for your response, here is a short test app I wrote that shows
the same behavior as the app I'm trying to write. The process I'm trying to
run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)


I'm sure an SCP program could be written directly in C#, although I
don't know if there are any SSH utility classes easily available. That
might be your best approach though.

Given that pscp is already using ANSI escape sequences to update single
lines, my guess is that the standard output reader is basically getting
a bit confused. I don't know if pscp is specifically written to notice
that the output is being redirected or not - it could just be that it's
not being flushed until the end if so, or something like that. I can
find out for you if you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
Okay, thanks for your response, here is a short test app I wrote that shows
the same behavior as the app I'm trying to write. The process I'm trying to
run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)


I'm sure an SCP program could be written directly in C#, although I
don't know if there are any SSH utility classes easily available. That
might be your best approach though.

Given that pscp is already using ANSI escape sequences to update single
lines, my guess is that the standard output reader is basically getting
a bit confused. I don't know if pscp is specifically written to notice
that the output is being redirected or not - it could just be that it's
not being flushed until the end if so, or something like that. I can
find out for you if you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
Thanks for your help. I was starting to think it might be a problem with
pscp itself rather than anything I'm doing. I was also thinking it might be
something to do with how the Process class works. I know from the MSDN docs
that if you redirect the stdout and don't read it, then it can fill the pipe
up and hang the process. I was wondering if there isn't a minimum amount of
data that needs to be written to the pipe before it'll let you read anything
at all from the parent process? Something like the data is only transferred
to the parent process in blocks of some minimum size to avoid slowing both
processes down?
Along the lines of writing an SCP program directly in C#, I know the source
code for Putty is available (it's in C), but I'm not sure I'd know where to
start with it! Maybe if I find myself with a lot of extra time on my hands
I'll try and figure it out. Unfortunately, they don't have it available as a
DLL. If anybody does know of some (free) SSH utility classes that I can use
in my app I'd certainly be grateful. I tried searching online, but didn't
find anything.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
Okay, thanks for your response, here is a short test app I wrote that shows the same behavior as the app I'm trying to write. The process I'm trying to run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)


I'm sure an SCP program could be written directly in C#, although I
don't know if there are any SSH utility classes easily available. That
might be your best approach though.

Given that pscp is already using ANSI escape sequences to update single
lines, my guess is that the standard output reader is basically getting
a bit confused. I don't know if pscp is specifically written to notice
that the output is being redirected or not - it could just be that it's
not being flushed until the end if so, or something like that. I can
find out for you if you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #10
Thanks for your help. I was starting to think it might be a problem with
pscp itself rather than anything I'm doing. I was also thinking it might be
something to do with how the Process class works. I know from the MSDN docs
that if you redirect the stdout and don't read it, then it can fill the pipe
up and hang the process. I was wondering if there isn't a minimum amount of
data that needs to be written to the pipe before it'll let you read anything
at all from the parent process? Something like the data is only transferred
to the parent process in blocks of some minimum size to avoid slowing both
processes down?
Along the lines of writing an SCP program directly in C#, I know the source
code for Putty is available (it's in C), but I'm not sure I'd know where to
start with it! Maybe if I find myself with a lot of extra time on my hands
I'll try and figure it out. Unfortunately, they don't have it available as a
DLL. If anybody does know of some (free) SSH utility classes that I can use
in my app I'd certainly be grateful. I tried searching online, but didn't
find anything.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
Okay, thanks for your response, here is a short test app I wrote that shows the same behavior as the app I'm trying to write. The process I'm trying to run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)


I'm sure an SCP program could be written directly in C#, although I
don't know if there are any SSH utility classes easily available. That
might be your best approach though.

Given that pscp is already using ANSI escape sequences to update single
lines, my guess is that the standard output reader is basically getting
a bit confused. I don't know if pscp is specifically written to notice
that the output is being redirected or not - it could just be that it's
not being flushed until the end if so, or something like that. I can
find out for you if you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #11
Thanks for your help. I was starting to think it might be a problem with
pscp itself rather than anything I'm doing. I was also thinking it might be
something to do with how the Process class works. I know from the MSDN docs
that if you redirect the stdout and don't read it, then it can fill the pipe
up and hang the process. I was wondering if there isn't a minimum amount of
data that needs to be written to the pipe before it'll let you read anything
at all from the parent process? Something like the data is only transferred
to the parent process in blocks of some minimum size to avoid slowing both
processes down?
Along the lines of writing an SCP program directly in C#, I know the source
code for Putty is available (it's in C), but I'm not sure I'd know where to
start with it! Maybe if I find myself with a lot of extra time on my hands
I'll try and figure it out. Unfortunately, they don't have it available as a
DLL. If anybody does know of some (free) SSH utility classes that I can use
in my app I'd certainly be grateful. I tried searching online, but didn't
find anything.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
Okay, thanks for your response, here is a short test app I wrote that shows the same behavior as the app I'm trying to write. The process I'm trying to run is pscp.exe which can be downloaded from here:
http://www.chiark.greenend.org.uk/~s.../download.html
(NB: If anybody knows a better way to do scp to a unix box, I'd be
interested to here about it.)


I'm sure an SCP program could be written directly in C#, although I
don't know if there are any SSH utility classes easily available. That
might be your best approach though.

Given that pscp is already using ANSI escape sequences to update single
lines, my guess is that the standard output reader is basically getting
a bit confused. I don't know if pscp is specifically written to notice
that the output is being redirected or not - it could just be that it's
not being flushed until the end if so, or something like that. I can
find out for you if you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #12
Matt Burland <wjousts@[nospam]hotmail.com> wrote:
Thanks for your help. I was starting to think it might be a problem with
pscp itself rather than anything I'm doing. I was also thinking it might be
something to do with how the Process class works. I know from the MSDN docs
that if you redirect the stdout and don't read it, then it can fill the pipe
up and hang the process. I was wondering if there isn't a minimum amount of
data that needs to be written to the pipe before it'll let you read anything
at all from the parent process?
I don't think so.
Something like the data is only transferred
to the parent process in blocks of some minimum size to avoid slowing both
processes down?
I think it's just a case of whether or not the other process has
flushed its output, although I could be wrong.
Along the lines of writing an SCP program directly in C#, I know the source
code for Putty is available (it's in C), but I'm not sure I'd know where to
start with it! Maybe if I find myself with a lot of extra time on my hands
I'll try and figure it out. Unfortunately, they don't have it available as a
DLL. If anybody does know of some (free) SSH utility classes that I can use
in my app I'd certainly be grateful. I tried searching online, but didn't
find anything.


I believe SSH involves quite a lot of state - making bits of Putty/pscp
etc available as a DLL would involve quite a lot of P/Invoking from C#.
If I get some free time in the near future, I might consider looking at
writing a library though - nothing very soon though, I'm afraid.

In the mean time, I suggest you email the Putty bugs/wishlist address
to ask about the flushing business - it could be fairly easy to fix.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #13
> > Along the lines of writing an SCP program directly in C#, I know the
source
code for Putty is available (it's in C), but I'm not sure I'd know where to start with it! Maybe if I find myself with a lot of extra time on my hands I'll try and figure it out. Unfortunately, they don't have it available as a DLL. If anybody does know of some (free) SSH utility classes that I can use in my app I'd certainly be grateful. I tried searching online, but didn't find anything.
I believe SSH involves quite a lot of state - making bits of Putty/pscp
etc available as a DLL would involve quite a lot of P/Invoking from C#.
If I get some free time in the near future, I might consider looking at
writing a library though - nothing very soon though, I'm afraid.


Let me know if you do write a library. I'd certainly be very interested.

In the mean time, I suggest you email the Putty bugs/wishlist address
to ask about the flushing business - it could be fairly easy to fix.

That sounds like a great idea, I think I'll do that.

Thanks again for your help.
Nov 15 '05 #14
On Sun, 5 Oct 2003 18:13:38 +0200, "Mr.Tickle" <Mr******@mrmen.com>
wrote:
public string m_ProcessArgs;
public string m_ProcessApp;
public string m_Password;

ewww, hungarian notation...


That's not even a variant of Hungarian notation. Hungarian notation
would be:

public string mstrProcessArgs;
public string mstrProcessApp;
public string mstrPassword;

Nov 15 '05 #15
In the mean time, I suggest you email the Putty bugs/wishlist address
to ask about the flushing business - it could be fairly easy to fix.

That sounds like a great idea, I think I'll do that.

Thanks again for your help.


Actually, I just fixed it myself!! It really was an easy fix in the end
(only one line added!), it just took me quite a while to figure out how to
recompile the whole thing, but once I remembered that there is a VS command
prompt in the VS tools folder it was easy to recompile with the makefile.
Works like a charm now. I quite impressed with myself!
Nov 15 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Al Cohen | last post by:
I'll start by warning that I'm a newbie to C# (but I've been programming for 25 years), so I may just be doing something reallyreally dumb. I'm writing a C# wrapper for a command-line application...
0
by: Matt Burland | last post by:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I start my process (which I do in a separate...
5
by: vijaynats | last post by:
Hi I created a windows app to run a dos batch file (which takes around 5mins to complete and generates lots of output messages on the console in the meantime)and i used RedirectStandardOuput to...
5
by: Tim | last post by:
Hi I am running a console program through my own VB front end. I am redirecting the StandardOut and StandardInput streams to and from textboxes so that the VB front end acts like a console. My...
6
by: Christophe Helfer | last post by:
hi, I have some problem with redirecting input and output from a process. Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) command line utility as redirecting its...
5
by: Markus S. | last post by:
Hello, I have a problem with a DOS EXE that is called by a .Net Winforms application. I need to redirect the console output into a textbox, but this should happen in real time, so when new...
1
by: rubikzube* | last post by:
I am attempting to place a call to make via System.Diagnostics.Process using the sample code below. If I comment out the two problem lines indicated, then the code runs smoothly and make performs...
3
by: Sudesh | last post by:
Hi, I am a newbie to C# and Im trying to redirect standard input, output and error of a console program written in C (MS VC 6.0) to a textbox on a form. The code for the redirecting looks like...
3
by: mhmtzdmr | last post by:
Hi, I want to run an application and capture its standard output. But the following code does not generate any output. Can anyone see something wrong? Public Sub RunApp(ByVal myprocess As...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
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,...
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...
0
tracyyun
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...
0
agi2029
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,...

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.