redirecting standard output of the process to file

P

PiotrKolodziej

Hi

I have a process that output i need to save in file.
Its a ping.exe. Iam sending 4 packets, and waiting for the process to exit.
First i tried to add arguments to the proces in such a way:

psi.Arguments = "192.168.1.1 > file.txt";

It didnt work.
So i tried to redirect output to the file by:

myProc.StartInfo.RedirectStandardOutput = true;
myProc.StartInfo.UseShellExecute = false;

myProc.Start();

string output = myProc.StandardOutput.ReadToEnd();
myProc.WaitForExit();

Now i can create file but problem is that user cannot see the progress. What
if ill send 30 packets?
How can i get the process output beeing able to see the progress of process
execution?

I would be grateful for reply.
Piotr Kolodziej
 
P

PiotrKolodziej

I did it this way:

string output = null;

while ((output = myProc.StandardOutput.ReadLine()) != null)
{
Console.WriteLine(output);
}

but i prefer to save output with UseShellExecute as true... If it is
possible
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top