I'm trying to capture the output from other applications. Capturing the output from ping works well. The variable output contains the expected output.
var p = new Process();
p.StartInfo.FileName = "ping";
p.StartInfo.Arguments = "www.google.com";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
But when I use this code for capturing the output of expdp (which is an oracle tool for exports), the variable is empty. Runnig the same command in the console will return some output.
p.StartInfo.FileName = "expdp";
p.StartInfo.Arguments = "help=y";
Am I missing something ?
Try checking the StandardError stream and see if you get anything there
var p = new Process();
p.StartInfo.FileName = "expdp";
p.StartInfo.Arguments = "help=y";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
var error = p.StandardError.ReadToEnd();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
one thing to note, If either your output stream or your error stram is too long, than this approach can cause deadlocks.
If that is the case, you'll have to read one of the streams asynchronously.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With