예제 #1
0
        private ProcessInfo CreateProcess(string clientPath, string arguments, string logPipeName)
        {
            var processStartInfo = new ProcessStartInfo
            {
                FileName        = clientPath,
                Arguments       = arguments,
                UseShellExecute = false,
            };

            var clientBinDirectory = _fs.Path.GetDirectoryName(_fs.Path.GetFullPath(clientPath));

            if (clientBinDirectory != null)
            {
                processStartInfo.WorkingDirectory = clientBinDirectory;
                _logger.Log($"Setting client working directory to: '{clientBinDirectory}'");
            }
            else
            {
                _logger.Log($"Failed to get client working directory from path: '{clientPath}'");
            }

            var process = new Process
            {
                StartInfo           = processStartInfo,
                EnableRaisingEvents = true,
            };

            foreach (var kp in _env)
            {
                processStartInfo.EnvironmentVariables[kp.Key] = kp.Value;
            }

            var namedPipeToLog = new NamedPipeToLog(_logger, logPipeName);

            process.Exited += (sender, eventArgs) =>
            {
                OnProcessExit?.Invoke(process);

                namedPipeToLog.Close();

                _logger.Log($"Process {process.Id} has exited");
            };

            if (!process.Start())
            {
                _logger.Log("Failed to start process");
                return(null);
            }

            namedPipeToLog.LogPrefix = $"(Pid: {process.Id}) ";
            namedPipeToLog.StartLogging();

            return(new ProcessInfo {
                Process = process
            });
        }
예제 #2
0
        private ProcessInfo CreateProcess(string clientPath, string arguments, string logPipeName)
        {
            var process = new Process
            {
                StartInfo =
                {
                    FileName        = clientPath,
                    Arguments       = arguments,
                    UseShellExecute = false
                },
                EnableRaisingEvents = true,
            };

            var namedPipeToLog = new NamedPipeToLog(_logger, logPipeName);

            process.Exited += (sender, eventArgs) =>
            {
                OnProcessExit?.Invoke(process);

                namedPipeToLog.Close();

                _logger.Log($"Process {process.Id} has exited");
            };

            if (!process.Start())
            {
                _logger.Log("Failed to start process");
                return(null);
            }

            namedPipeToLog.LogPrefix = $"(Pid: {process.Id}) ";
            namedPipeToLog.StartLogging();

            return(new ProcessInfo {
                Process = process
            });
        }