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

  • 相关阅读:
    Java速成笔记
    C语言学习笔记
    形式语义05 Semantics
    密码学04 PRG&PRF
    形式语义04 Types
    密码学03 Computational
    形式语义03 Lambda
    密码学02 Perfect
    形式语义01 Intro
    密码学01 Intro
  • 原文地址:https://www.cnblogs.com/rickiedu/p/1499794.html
Copyright © 2011-2022 走看看