Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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#程序捕获c#可执行输出_C#_.net_Console Application_Outputstream - Fatal编程技术网

从另一个c#程序捕获c#可执行输出

从另一个c#程序捕获c#可执行输出,c#,.net,console-application,outputstream,C#,.net,Console Application,Outputstream,我正在执行一个C#程序,即另一个C#程序的.exe。但是.exe的程序中有一些Console.WriteLine()。我想把标准输出输入到我的C#程序中 比如说, 考虑一个C#可执行文件,即1.exe,还有另一个程序2.cs 我是从2.cs 1.exe拨打的。现在控制台从1显示一些输出。exe。但我想在我的程序2.cs中输出。用于向用户显示信息 可能吗?请帮忙 谢谢 Sai sindhu您可以使用ProcessStartInfo.RedirectStandardOutput属性 Process

我正在执行一个C#程序,即另一个C#程序的.exe。但是.exe的程序中有一些Console.WriteLine()。我想把标准输出输入到我的C#程序中

比如说,

考虑一个C#可执行文件,即1.exe,还有另一个程序2.cs

我是从2.cs 1.exe拨打的。现在控制台从1显示一些输出。exe。但我想在我的程序2.cs中输出。用于向用户显示信息

可能吗?请帮忙

谢谢
Sai sindhu

您可以使用ProcessStartInfo.RedirectStandardOutput属性

Process compiler = new Process();
compiler.StartInfo.FileName = "csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();    

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();

您必须重定向标准输出流,请查看以了解更多信息

当进程将文本写入其标准流时,该文本为 通常显示在控制台上。通过重定向StandardOutput 流,您可以操纵或抑制进程的输出。对于 例如,您可以过滤文本、以不同的格式设置文本或编写 输出到控制台和指定的日志文件


可能重复的请记住在发布前搜索堆栈溢出以查找类似问题。还要注意在创建问题时弹出的建议问题-我几乎可以肯定上面的问题会出现。