C#操作DOS命令,并获取处理返回值

// /*----------------
// // 文件名:Method
// // 文件功能描述:
// //    使用 ADB 来进行安卓设备与PC端之间的文件交互,具体adb命令操作请百度查阅
// //
// // 创建标识:20140526
// //
// // 修改标识:
// // 修改描述:

// //----------------------------------------------------------------*/

            
            string cmd = Directory.GetCurrentDirectory();
            cmd = cmd.Substring(0, cmd.IndexOf("bin\")) + @"platform-toolsadb.exe";
            ProcessStartInfo psi = new ProcessStartInfo(cmd, "get-state");
 
            psi.CreateNoWindow = true;//不显示dos命令行窗口
            psi.RedirectStandardOutput = true;//
            psi.RedirectStandardInput = true;//   
            psi.UseShellExecute = false;//是否指定操作系统外壳进程启动程
 
            Process p = Process.Start(psi);
            StreamReader reader = p.StandardOutput;//截取输出流   
            string line = reader.ReadLine();//每次读取一行
            //while (!reader.EndOfStream)
            //{
            // Console.Out.WriteLine(line);
            // line = reader.ReadLine();
            //}
            if (!line.Equals("device"))
            {
                MessageBox.Show("设备未就绪,请查看数据线是否正常连接电脑后重试", "设备未就绪", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            Directory.CreateDirectory("d://file");
            psi.Arguments="pull /sdcard/file/ d:/file";
            p = Process.Start(psi);
            p.WaitForExit();
            p.Close();//关闭进程   
            reader.Close();//关闭流 
原文地址:https://www.cnblogs.com/minily/p/7390313.html