예제 #1
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            Console.WriteLine($"App: {Assembly.GetEntryAssembly().FullName}");
            Console.WriteLine($"Executing from folder: {Environment.CurrentDirectory}");
            Console.WriteLine($"at: {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
            Console.WriteLine($"With args: [{string.Join(" ", args.Skip(1))}]");

            if (args.Length == 1 && args[0].ToLower().StartsWith("-delay:"))
            {
                int millisec;
                if (Int32.TryParse(args[0].Substring(args[0].IndexOf(":") + 1), out millisec))
                {
                    Console.WriteLine($"Sleeping for {millisec} milliseconds and will exit.");
                    Thread.Sleep(millisec);
                }
                else
                {
                    Console.Error.WriteLine("Error while trying to read the delay.");
                    Environment.ExitCode = -99;
                }
            }
            else
            {
                if (args.Length == 0)
                {
                    Console.Error.WriteLine($"Can't forward execution. There is no argument (executable) provided.");
                    Environment.ExitCode = -99;
                }
                else
                {
                    var result = ProcessExecutionWithOutputCapture.ExecuteWith(args[0], string.Join(" ", args.Skip(1)));

                    Console.Write(result.Output);
                    Console.Error.Write(result.Error);

                    Environment.ExitCode = result.ExitCode;
                }
            }

            Console.WriteLine($"Done in {stopwatch.ElapsedMilliseconds} millisecs");
        }
예제 #2
0
        // ************************************************************************
        public static ProcessWithOutputCaptureResult Execute(string executablePath, string arguments, int timeout = Timeout.Infinite, ProcessWindowStyle processWindowStyle = ProcessWindowStyle.Hidden)
        {
            var p = new ProcessExecutionWithOutputCapture();

            return(p.ExecuteInternal(executablePath, arguments, timeout, processWindowStyle));
        }