我编写了一个批处理文件,该文件使用ADB方法将输出返回到cmd窗口。
但是,当我从Windows窗体程序(用C#编写)中将此文件作为进程启动时,返回的输出不是cmd窗口中的输出。
示例:
从cmd窗口:“错误:找不到设备/模拟器”
从输出字符串:“”(在这种情况下没有输出,不同的情况 - 只是输出的一部分)。
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
如何获得此批处理文件的完整输出?
答案 0 :(得分:0)
看起来你应该使用
process.StandardError.ReadToEnd();
和
process.StandardOutput.ReadToEnd();
<强> 说明: 强>
每个应用程序有2个输出,stdout和stderr
似乎发生的事情是你只抓住你的进程的stdout,而不是stderr。
如果出现错误,您也可以抛出异常。
类似
[...]
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if(!error.equals(""))
throw new Exception(error);
return output;