zoukankan      html  css  js  c++  java
  • 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();//关闭流 
  • 相关阅读:
    jQuery UI vs EasyUI
    javascript数组元素的添加、删除与插入以及参数数组的使用
    ExtJS中get、getDom、getCmp、getBody、getDoc使用
    ASP.net 中 OutputCache 指令各个参数的作用
    母版页如何页面部分缓存
    Cache OutputCache ASP.NET缓存
    如何使用 @ OutputCache 指令的 VaryByCustom 属性来缓存不同版本的页面
    页面级缓存@ OutputCache
    存储过程DataGrid分页及注意点
    vs2005中 Global.asax 没有 Global.asax.cs 问题解决
  • 原文地址:https://www.cnblogs.com/minily/p/7390313.html
Copyright © 2011-2022 走看看