简体   繁体   English

使用c#中的Process通过ProcessStartInfo.Arguments中的>重定向输出

[英]Redirect output using Process in c# with > in ProcessStartInfo.Arguments

I want to redirect output to a file but I don't want to do it through the arguments like so: 我想将输出重定向到文件,但是我不想通过这样的参数来做到这一点:

ProcessStartInfo sInfo = new ProcessStartInfo();
sInfo.FileName = "test.exe";
sInfo.Arguments = "> test.log";
Process myProc = new Process();
myProc.StartInfo = sInfo;
myProc.Start();

It seems if I do that, it just flat out doesn't work. 看来,如果我这样做,则无法正常工作。 Any ideas how or a way around it? 有什么想法或解决方法吗?

最好的方法是使用流阅读器:首先使用ProcessStartInfo类启动该过程,然后使用RedirectStandardOutput并将其作为布尔值设置为true,现在启动您的过程并使用StreamReader读取文件,可以在此处找到更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM