1

Closed

shelling to chutzpah.console.exe from C# never returns

description

Hello!

I'm trying to shell to the version 2.5.0 console exe and when kicking off the process from C# the process hangs and never returns. I have to loop and interrogate StdOut to know the task is complete. Using process.WaitForExit, or hooking the Process_Exited event both hang until I grow frustrated and kill them.

Using the following code, the arguments variable is set to
/debug /file chutzpah_test_runner.html

chutzpah_test_runner.html is a copy of jasmine.html with the placeholders replaced by all of the test files.

I'm attached a VS2012 repro demo. Had to remove Phantom.exe and the json.net nuget package to be under the 4 MB limit. You can either run the console app, or the unit test in the Build project.

Uncomment this section to see the error (hopefully):
            // THIS DOES NOT WORK - NEVER RETURNS
            //process.WaitForExit(1000 * 60 * secondsToWait);
Here is the relevant code...
            var process = new Process()
            {
                StartInfo = new ProcessStartInfo()
                {
                    FileName = executable,
                    Arguments = arguments,
                    WorkingDirectory = workingDirectory,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    UseShellExecute = false
                }
            };

            process.Start();

            var secondsToWait = 20;

            string IsComplete = "Tests complete";
            string NoTests = "0 total, 0 failed";
            string output = string.Empty;

            // THIS DOES NOT WORK - NEVER RETURNS
            //process.WaitForExit(1000 * 60 * secondsToWait);

            // THIS DOES WORK

            // wait for 20 seconds total
            // check each second to see if the process has exited
            for (var i = 0; i < secondsToWait; i++)
            {
                output = process.StandardOutput.ReadToEnd();
                if (output.Contains(IsComplete) || output.Contains(NoTests))
                {
                    break;
                }
                else
                {
                    Debug.WriteLine("Waiting {0} of {1} seconds for results...", i + 1, secondsToWait);
                    process.Refresh();
                    Thread.Sleep(1000);
                }
            }

            string error = process.StandardError.ReadToEnd();

            process.Close();
            return string.IsNullOrEmpty(error) && !output.Contains(NoTests) && TestsPassed(output);
Any thoughts??

PS: This works just perfectly when I run this from the command line. It only doesn't work when I run this from within C#...

Thanks!
Thad

file attachments

Closed May 16 at 2:55 PM by mmanela
user issue

comments

mmanela wrote Oct 8, 2013 at 4:02 PM

You must first read from StandardOut before the process can exit.
If you put this line
process.StandardOutput.ReadToEnd();
before your waitForExit call it should work.

thadeusd wrote Oct 9, 2013 at 2:12 PM

Well... Shoot... You are very correct. I obviously missed that on all of the examples I reviewed. Sorry about that.