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

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

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

            
            string cmd = Directory.GetCurrentDirectory();
            cmd = cmd.Substring(0, cmd.IndexOf("bin\\")) + @"platform-tools\adb.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值