1

I wrote a batch file that uses ADB methods that return output to the cmd window.

However, when I start this file as a process from my Windows Forms program (written in C#) the output returned isn't the one in the cmd window.


Example:

From the cmd window: "error: no devices/emulators found"

From the output string: "" (No output in this case, different cases- just part of the output).


Process process = new Process();
process.StartInfo.FileName = filePath;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output; // Not the same as the cmd window

How can I get the full output of this batch file?

1 Answer 1

0

it looks like you should use

process.StandardError.ReadToEnd();

and

process.StandardOutput.ReadToEnd();

Explanation:

there's 2 outputs for each application, stdout and stderr

  • stdout (STanDard OUTput) is for general purpose output.
  • stderr (STanDard ERRor) is for errors.

what seems to happen is that you grab only the stdout of your process, and not the stderr.

you can also want to throw an exception in case you have an error.

something like

[...]
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if(!error.equals("")) 
    throw new Exception(error);
return output;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.