为什么C#ProcessStartInfoRedirectStandardOutput导致XCOPY过程失败 [英] Why would C# ProcessStartInfoRedirectStandardOutput cause xcopy process to fail

查看:1245
本文介绍了为什么C#ProcessStartInfoRedirectStandardOutput导致XCOPY过程失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有点痛,因为我现在没有code在我面前,但我会尽力解释。

This is a bit of a pain because I now don't have the code in front of me, but I'll try to explain.

我有一个简单的C#应用​​程序,它揭开序幕的Ruby脚本(它做了一些其他的东西,所以它会生成一个批处理文件并执行)。

I have a simple C# application that kicks off a Ruby script (it does a couple of other things, so it generates a batch file and executes that).

我现在用的是C#程序对象,我设置以下 redirectstandardoutput =真 redirectstandarderror =真 UseShellExecute =假 CreateNoWindow =真(向后逻辑有可爱的一点!)

I am using the C# process object and I set the following redirectstandardoutput = true redirectstandarderror = true UseShellExecute = false CreateNoWindow = true (lovely bit of backwards logic there!)

我再创建两个线程和轮询的ReadLine()为错误和输出流,等待他们俩完成之前,我打电话WaitForExit()。

I then create two threads and poll ReadLine() for both the error and output streams, waiting for them both to finish before I call WaitForExit().

现在,无论我做什么我Ruby脚本无法调用系统(XCOPY ...)命令时,我重定向输出(生成它只是不会复制任何错误)。它也不会复制我问它来复制其他文件。

Now, no matter what I do my Ruby script fails to call a system("xcopy...") command when I redirect the output (no errors are generated it just doesn't copy). It also doesn't copy other files I ask it to copy.

这会发生,如果我直接两个流一个线程,他们中的一个,只是重定向他们中的一个,只是调用ReadToEnd()。

This happens if I direct both streams to a thread, one of them, only redirect one of them and just call ReadToEnd().

这只是正常工作,如果我设置redirectstandardoutput和redirectstandarderror为false。

It only works correctly if I set redirectstandardoutput and redirectstandarderror to false.

我在这里全盘损失。我想也许输出流被填充起来,但我不能想象为什么,如果我打电话的ReadLine(我需要读取行,所以我可以分析每一行,只有present相关的多个最终用户)。我也想,也许调用从螺纹C#程序DOS命令可能会出现问题。

I'm at a total loss here. I thought maybe the output stream was being filled up, but I can't imagine why if I'm calling ReadLine (I need read line so I can parse each line and only present relevant ones to the end user). I also thought maybe calling dos commands from a threaded C# process might cause problems.

有没有人有任何想法可能是怎么回事?我应该说我在VS .NET 2005,我认为这是在.NET Framework 2.0。

Does anyone have any idea what might be going on here? I should say I'm on VS .net 2005, which I think is the .Net Framework 2.0.

推荐答案

有一个<一个href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/ab3c0cc7-83c2-4a86-9188-40588b7d1a52/">obscure张贴在MSDN论坛这似乎表明,有可能是一个小故障与XCOPY本身 - 如果您重定向XCOPY的STDOUT,你还必须重定向标准输入

There is an obscure post on the MSDN forums that seems to indicate that there may be a glitch with XCOPY itself -- if you redirect XCOPY's STDOUT, you must also redirect STDIN.

注:我打这个社区维基,让别人谁知道红宝石可以写一些例如code到重定向标准输入系统()的)

这篇关于为什么C#ProcessStartInfoRedirectStandardOutput导致XCOPY过程失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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