zoukankan      html  css  js  c++  java
  • Process.Start调用CMD

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;

    namespace SocketDemo {
        class Program {
            static void Main() {
                Process proc = new Process();
                proc.StartInfo.FileName = "net.exe";
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.Arguments = "view";
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.UseShellExecute = false;
                proc.Start();

                StreamReader sr = new StreamReader(proc.StandardOutput.BaseStream);
                string line = "";
                List<string> names = new List<string>();

                while ((line = sr.ReadLine()) != null) {
                    //                if (line.StartsWith(@"\\")) {
                    names.Add(line); //.Substring(2).TrimEnd());
                    //                }
                }

                sr.Close();
                proc.WaitForExit();

                foreach (string name in names) {
                    Console.WriteLine(name);
                }

                Console.ReadKey();
            }
        }
    }

  • 相关阅读:
    删除重复数据
    jquery删除文件
    统计目录下文件数及大小
    koa generator
    如何做单测? 单测和开发占比应该是多少?集成测试
    webpack之loader和plugin简介
    服务端渲染
    请求头包含哪些部分
    vue的高阶组件
    amd,cmd规范
  • 原文地址:https://www.cnblogs.com/rickiedu/p/1499794.html
Copyright © 2011-2022 走看看