tags:

views:

321

answers:

2

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.

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).

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!)

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().

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.

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

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

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.

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.

A: 

Would you mind posting a code snippet for what you are doing? I have a lot of questions about the specifics of how you are doing this (in theory what you are doing sounds correct, which means it's probably a small bug).

overstood
+4  A: 

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.

(note: I'm marking this a community wiki, so somebody who knows ruby could write some example code to redirecting STDIN for system())

Alex Lyman
This was the problem. I simply set processToRun.StartInfo.RedirectStandardInput = true and xcopy worked perfectly. Funnily enough when I had the output working, I was going to redirect the input anyway.
Lee Winder