Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Captured output is empty

Tags:

c#

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 ?

like image 872
user49126 Avatar asked May 14 '26 18:05

user49126


1 Answers

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.

like image 74
Sam I am says Reinstate Monica Avatar answered May 16 '26 07:05

Sam I am says Reinstate Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!