コード例 #1
0
        public async Task <bool> LaunchProcessAsync(TestProcessStartInfo runtimeProcessStartInfo, CancellationToken cancellationToken)
        {
            return(await Task.Run(() =>
            {
                try
                {
                    EqtTrace.Verbose("RuntimeManager: Starting process '{0}' with command line '{1}'", runtimeProcessStartInfo.FileName, runtimeProcessStartInfo.Arguments);

                    cancellationToken.ThrowIfCancellationRequested();

                    var callbacks = new ProcessCallbacks
                    {
                        outputReceived = this.ProcessOutputReceived,
                        errorReceived = this.ProcessErrorReceived,
                        exitReceived = this.ProcessExitReceived
                    };

                    this.jsProcess.LaunchProcess(runtimeProcessStartInfo, callbacks);
                }
                catch (OperationCanceledException ex)
                {
                    EqtTrace.Error("RuntimeManager: Failed to launch node: {0}", ex);
                    Console.WriteLine(ex);
                    return false;
                }

                this.InitializeCommunication(cancellationToken);
                return this.jsProcess.IsAlive;
            }));
        }
コード例 #2
0
        public bool LaunchProcess(TestProcessStartInfo startInfo, ProcessCallbacks processStreamCallbacks)
        {
            var endpoint = this.InitializeChannel();

            var process = new Process();

            try
            {
                this.InitializeStartInfo(process, startInfo, endpoint);

                process.EnableRaisingEvents = true;
                process.OutputDataReceived += (sender, args) => processStreamCallbacks.outputReceived(sender as Process, args.Data);
                process.ErrorDataReceived  += (sender, args) => processStreamCallbacks.errorReceived(sender as Process, args.Data);
                process.Exited += (sender, args) =>
                {
                    // Call WaitForExit without again to ensure all streams are flushed,
                    var exitingProcess = sender as Process;
                    try
                    {
                        // Add timeout to avoid indefinite waiting on child process exit.
                        if (exitingProcess.WaitForExit(500))
                        {
                            Console.WriteLine("JSTest: Process with id {0} exited successfully.", jsProcessId);
                        }
                        else
                        {
                            Console.Error.WriteLine("JSTest: WaitForExit timed out for process {0}.{1}", jsProcessId);
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        Console.WriteLine("JSTest: Process with id {0} exited successfully.{1}", jsProcessId);
                    }

                    // If exit callback has code that access Process object, ensure that the exceptions handling should be done properly.
                    processStreamCallbacks.exitReceived(exitingProcess);
                };

                EqtTrace.Verbose("JSProcess: Starting process '{0}' with command line '{1}'", startInfo.FileName, startInfo.Arguments);

                process.Start();
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
                this.jsProcessId = process.Id;
            }
            catch (Exception exception)
            {
                process.Dispose();
                process = null;

                EqtTrace.Error("JSProcess: Test runner {0} failed to launch with the following exception: {1}", startInfo.FileName, exception.Message);
                throw;
            }

            this.process = process;

            this.channel.WaitForClientConnection(GetConnectionTimeout());

            return(process != null);
        }