コード例 #1
0
ファイル: ProcessRunner.cs プロジェクト: wlclass/Photon
        public async Task <ProcessResult> RunAsync(ProcessRunInfo info, CancellationToken token = default(CancellationToken))
        {
            using (var process = Start(info)) {
                if (process == null)
                {
                    throw new ApplicationException("Failed to start process!");
                }

                var p = process;
                using (token.Register(() => p.Kill())) {
                    var readOutTask   = ReadToOutput(process.StandardOutput, ConsoleColor.Gray, token);
                    var readErrorTask = ReadToOutput(process.StandardError, ConsoleColor.DarkYellow, token);

                    await Task.Run(() => p.WaitForExit(), token);

                    await Task.WhenAll(readOutTask, readErrorTask);

                    return(new ProcessResult {
                        ExitCode = process.ExitCode,
                        Output = readOutTask.Result,
                        Error = readErrorTask.Result,
                    });
                }
            }
        }
コード例 #2
0
        public async Task <ProcessResult> RunAsync(ProcessRunInfo info, CancellationToken cancelToken = default(CancellationToken))
        {
            var runner = new ProcessRunner(context);
            var result = await runner.RunAsync(info, cancelToken);

            ProcessResult(result);
            return(result);
        }
コード例 #3
0
        public ProcessResult Run(ProcessRunInfo info, CancellationToken cancelToken = default(CancellationToken))
        {
            var runner = new ProcessRunner(context);
            var result = runner.Run(info, cancelToken);

            ProcessResult(result);
            return(result);
        }
コード例 #4
0
        public async Task <ProcessResult> RunAsync(string command, CancellationToken cancelToken = default(CancellationToken))
        {
            var runner    = new ProcessRunner(context);
            var arguments = ProcessRunInfo.FromCommand(command);
            var result    = await runner.RunAsync(arguments, cancelToken);

            ProcessResult(result);
            return(result);
        }
コード例 #5
0
        public ProcessResult Run(string command, CancellationToken cancelToken = default(CancellationToken))
        {
            var runner    = new ProcessRunner(context);
            var arguments = ProcessRunInfo.FromCommand(command);
            var result    = runner.Run(arguments, cancelToken);

            ProcessResult(result);
            return(result);
        }
コード例 #6
0
        protected ProcessRunInfo GetProcessArgs(string arguments)
        {
            var info = new ProcessRunInfo {
                Filename    = Exe,
                Arguments   = arguments,
                EchoCommand = EchoCommand,
            };

            if (!string.IsNullOrEmpty(WorkingDirectory))
            {
                info.WorkingDirectory = WorkingDirectory;
            }

            return(info);
        }
コード例 #7
0
ファイル: ProcessRunner.cs プロジェクト: wlclass/Photon
        public SysProcess Start(ProcessRunInfo info)
        {
            if (info.Filename == null)
            {
                throw new ArgumentNullException(nameof(info.Filename));
            }

            var startInfo = new ProcessStartInfo {
                FileName               = info.Filename,
                Arguments              = info.Arguments,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            if (!string.IsNullOrEmpty(info.WorkingDirectory))
            {
                startInfo.WorkingDirectory = info.WorkingDirectory;

                var parts     = info.Filename.Split(Path.DirectorySeparatorChar);
                var firstPart = parts.FirstOrDefault();

                if (firstPart == "." || firstPart == "..")
                {
                    var _p = Path.Combine(info.WorkingDirectory, info.Filename);
                    startInfo.FileName = Path.GetFullPath(_p);
                }
            }

            foreach (var key in info.EnvironmentVariables.Keys)
            {
                startInfo.EnvironmentVariables[key] = info.EnvironmentVariables[key];
            }

            Output?.WriteActionBlock(context, $"Run Command: {info.Filename} {info.Arguments}");

            return(SysProcess.Start(startInfo));
        }