Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 由我的程序启动的批处理文件进程不';t返回完整输出_C#_Batch File_Process_Output - Fatal编程技术网

C# 由我的程序启动的批处理文件进程不';t返回完整输出

C# 由我的程序启动的批处理文件进程不';t返回完整输出,c#,batch-file,process,output,C#,Batch File,Process,Output,我编写了一个批处理文件,它使用将输出返回到cmd窗口的方法 但是,当我从Windows窗体程序(用C#编写)将此文件作为进程启动时,返回的输出不是cmd窗口中的输出 例如: 从cmd窗口:“错误:未找到设备/模拟器” 来自输出字符串:“”(本例中没有输出,不同的情况-只是输出的一部分) 如何获得此批处理文件的完整输出?看起来您应该使用 process.StandardError.ReadToEnd(); 和 process.StandardOutput.ReadToEnd(); 说明:

我编写了一个批处理文件,它使用将输出返回到cmd窗口的方法

但是,当我从Windows窗体程序(用C#编写)将此文件作为进程启动时,返回的输出不是cmd窗口中的输出


例如:

从cmd窗口:“错误:未找到设备/模拟器”

来自输出字符串:“”(本例中没有输出,不同的情况-只是输出的一部分)




如何获得此批处理文件的完整输出?

看起来您应该使用

process.StandardError.ReadToEnd();

process.StandardOutput.ReadToEnd();
说明:

每个应用程序有两个输出,stdout和stderr

  • 标准输出用于通用输出
  • 标准错误是指错误
似乎发生的是,您只获取流程的标准,而不是标准

如果出现错误,也可以抛出异常

差不多

[...]
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if(!error.equals("")) 
    throw new Exception(error);
return output;

看起来你应该使用

process.StandardError.ReadToEnd();

process.StandardOutput.ReadToEnd();
说明:

每个应用程序有两个输出,stdout和stderr

  • 标准输出用于通用输出
  • 标准错误是指错误
似乎发生的是,您只获取流程的标准,而不是标准

如果出现错误,也可以抛出异常

差不多

[...]
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if(!error.equals("")) 
    throw new Exception(error);
return output;