如何在另一个文件夹中获取调试文件夹中的输出 [英] How do I obtain the output in debug folder also in another folder

查看:85
本文介绍了如何在另一个文件夹中获取调试文件夹中的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button35_Click_1(object sender, EventArgs e)
       {
           string str = @"C:\output\run\Ocirc.exe";
           Process process = new Process();
           process.StartInfo.FileName = str;
           process.Start();
       }





我的尝试:



这里获得的代码输出存储在debug文件夹中,但我需要在相应的文件中获取输出而不是仅调试。



What I have tried:

here in the code output obtained is stored in debug folder,but i need to obtained the output in corresponding files rather than only debug.

推荐答案

我会在网上搜索C#Spawn流程重定向输出..有很多例子..本质上你最终会做类似的事情



I would search the net for C# Spawn process redirect output .. there are plenty of examples .. in essence you end up doing something like

process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += (sender, args) => Console.WriteLine("received output: {0}", args.Data);
process.Start();
process.BeginOutputReadLine();





您可以用您选择的文件替换Console.WriteLine ...



您还可以通过添加来获取标准错误





where you would replace the Console.WriteLine with a write to a file of your choice ...

you can also capture standard error by adding

RedirectStandardError = true 

process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data); 

process.BeginErrorReadLine();





此代码不是我的,顺便说一句,这要感谢Judah Himango(我曾经在这里看过一段时间的人)



这是你的另一个首发启动流程并捕获其输出(C#)·GitHub [ ^ ]


这篇关于如何在另一个文件夹中获取调试文件夹中的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆