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();
            }
        }
    }

  • 相关阅读:
    git的使用
    每个JavaScript开发人员应该知道的33个概念
    JavaEE实战——XML文档DOM、SAX、STAX解析方式详解
    Java-函数式编程(三)流(Stream)
    Spring高级装配(二) 条件化的bean
    Spring高级装配(一) profile
    Spring Bean装配学习
    Java7任务并行执行神器:Fork&Join框架
    Stream:java1.8新特性
    java基础
  • 原文地址:https://www.cnblogs.com/rickiedu/p/1499794.html
Copyright © 2011-2022 走看看