473,385 Members | 1,730 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,385 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 3051
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.