Ejemplo n.º 1
0
        public static string ExecuteBat(this System.Diagnostics.Process process, string batToExecute)
        {
            string        path        = Path.GetRandomFileName() + ".bat";
            StreamWriter  swBat       = File.CreateText(path);
            StringBuilder informacion = new StringBuilder();
            StreamReader  str;

            swBat.Write(batToExecute);
            swBat.Close();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.FileName = path;
            startInfo.Hide();
            process.StartInfo = startInfo;
            process.Start();
            str = process.StandardOutput;
            while (!str.EndOfStream)
            {
                informacion.Append((char)str.Read());
            }
            str.Close();
            File.Delete(path);
            return(informacion.ToString().Substring(informacion.ToString().IndexOf('>') + batToExecute.Length + 4));
        }