Ejemplo n.º 1
0
        public static bool Execute(ICmdProcessCaller processCaller, string command, Action <StreamReader> resultAction = null)
        {
            Stopwatch sw      = Stopwatch.StartNew();
            var       process = processCaller.Call(command);

            if (process is null || process.StartInfo?.FileName != FileName)
            {
                return(false);
            }
            Console.WriteLine($"{nameof(DotnetCmdProcessHelper)} executes 'dotnet {command}'");
            using (var sr = process.StandardOutput)
            {
                if (resultAction is null)
                {
                    Console.WriteLine(sr.ReadToEnd());
                }
                else
                {
                    resultAction.Invoke(sr);
                }
            }
            sw.Stop();
            Console.WriteLine($"{nameof(DotnetCmdProcessHelper)} runs {sw.ElapsedMilliseconds}ms");
            process.Dispose();
            return(true);
        }