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

  • 相关阅读:
    笨办法学习python之hashmap
    python实现三级菜单源代码
    ql的python学习之路-day3
    ql的python学习之路-day2
    Spring的数据库开发
    Spring学习之Aspectj开发实现AOP
    spring学习之依赖注入DI与控制反转IOC
    spring学习之第一个spring程序
    spring学习之spring入门
    Java线程(一)——创建线程的两种方法
  • 原文地址:https://www.cnblogs.com/rickiedu/p/1499794.html
Copyright © 2011-2022 走看看