I have a Process:
Process pr = new Process();
pr.StartInfo.FileName = @"wput.exe";
pr.StartInfo.Arguments = @"C:\Downloads\ ftp://user:dvm@172.29.200.158/Transfer/Updates/";
pr.StartInfo.RedirectStandardOutput = true;
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.
pr.Start();
string output = pr.StandardOutput.ReadToEnd();
Console.WriteLine("Output:");
Console.WriteLine(output);
Wput is an ftp upload client.
At the moment when I run the process and begin the upload, the app freezes and the console output won’t show until the end. I guess the first problem is solvable by using a Thread.
What I want to do is start an upload, have it pause every so often, read whatever output has been generated (use this data do make progress bar etc), and begin again.
What classes/methods should I be looking into?
You can use the
OutputDataReceivedevent to print the output asynchronously. There are a few requirements for this to work:An example of this working is below. It’s just doing a long running operation that also has some output (
findstr /lipsn foo *on C:\ — look for “foo” in any file on the C drive). TheStartandBeginOutputReadLinecalls are non-blocking, so you can do other things while the console output from your FTP application rolls in.If you ever want to stop reading from the console, use the
CancelOutputRead/CancelErrorReadmethods. Also, in the example below, I’m handling both standard output and error output with a single event handler, but you can separate them and deal with them differently if needed.