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();//关闭流 
  • 相关阅读:
    Cesium深入浅出之视频投影【转】
    前端面试题总结[转]
    Cesium 做汉化的另一种思路。[转]
    Cesium深入浅出之可视域分析【转】
    Python 3's fStrings: An Improved String Formatting Syntax (Guide)
    登录远程主机执行重启服务
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pipbuild*解决办法
    服务器磁盘使用率高做钉钉报警
    Shell 使用 pushd 和 popd实现快速定位
    Let’s Encrypt配置ssl证书自动更新
  • 原文地址:https://www.cnblogs.com/minily/p/7390313.html
Copyright © 2011-2022 走看看