コード例 #1
0
        private async Task <string> ExecuteShellCommand(string cmd)
        {
            // creating temp bat file
            string tempfilePath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".bat";

            File.WriteAllText(tempfilePath, cmd);

            // executing temp bat file
            ProcessStartInfo procInfo = new ProcessStartInfo("cmd", $"/C {tempfilePath}");

            procInfo.RedirectStandardOutput = true;
            procInfo.UseShellExecute        = false;
            procInfo.CreateNoWindow         = true;
            procInfo.WindowStyle            = ProcessWindowStyle.Hidden;

            // creating process and reading STDOUT
            logger.Debug($"Starting new process to fetch commits with cmd: {cmd}");
            Process proc = new Process();

            proc.StartInfo = procInfo;
            proc.Start();
            return(await proc.StandardOutput.ReadToEndAsync());
        }