private static string CMDPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\cmd.exe"; public static void RunCMDCommand(string Command, out string OutPut)
{
using (Process pc = new Process())
{
Command = Command.Trim().TrimEnd('&') + "&exit"; pc.StartInfo.FileName = CMDPath;
pc.StartInfo.CreateNoWindow = true;
pc.StartInfo.RedirectStandardError = true;
pc.StartInfo.RedirectStandardInput = true;
pc.StartInfo.RedirectStandardOutput = true;
pc.StartInfo.UseShellExecute = false; pc.Start(); pc.StandardInput.WriteLine(Command);
pc.StandardInput.AutoFlush = true; OutPut = pc.StandardOutput.ReadToEnd();
int P = OutPut.IndexOf(Command) + Command.Length;
OutPut = OutPut.Substring(P, OutPut.Length - P - 3);
pc.WaitForExit();
pc.Close();
}
}

使用:

RunCMDCommand("wmic cpu get name", out string cpuInfo);

cpuInfo = cpuInfo.Replace("Name", "").Replace("\n", "").Trim();

获取CPUID

   wmic CPU get ProcessorID
关注公众号githubcn,免费获取更多学习视频教程

c# 调用CMD命令并获取输出结果的更多相关文章

  1. C语言使用cmd命令并获取输出方法

    转自http://blog.csdn.net/hxh129/article/details/8000205 C语言使用cmd命令并获取输出方法 在实践中,我们有时候需要用C语言来调用cmd的命令,并得 ...

  2. java执行cmd命令并获取输出结果

    1.java执行cmd命令并获取输出结果 import java.io.BufferedReader; import java.io.InputStreamReader; import org.apa ...

  3. JAVA中调用CMD命令,并输出运行结果

    package com.wzw.util; import java.io.BufferedReader; import java.io.InputStreamReader; public class ...

  4. Python执行Linux cmd命令,获取输出的一种方法,输出是bytes

    import subprocess p = subprocess.Popen('df -lh', stdout=subprocess.PIPE, shell=True) print(p.stdout. ...

  5. SQL server 存储过程 C#调用Windows CMD命令并返回输出结果 Mysql删除重复数据保留最小的id C# 取字符串中间文本 取字符串左边 取字符串右边 C# JSON格式数据高级用法

    create proc insertLog@Title nvarchar(50),@Contents nvarchar(max),@UserId int,@CreateTime datetimeasi ...

  6. python调用cmd显示中文乱码及调用cmd命令

    os.system('dir') 解决方法加上 os.system('chcp 65001') ____________________________________________________ ...

  7. 使用node自动生成html并调用cmd命令提交代码到仓库

    生成html提交到git仓库 基于目前的express博客,写了一点代码,通过request模块来请求站点,将html保存到coding-pages目录,复制静态文件夹到coding-pages,最后 ...

  8. 通过CMD命令窗口获取django版本号

    通过CMD命令窗口获取django版本号 方法一: C:\Users\Administrator>python >>> import django >>> d ...

  9. Python调用cmd命令

    常用的两种方式: 1.python的OS模块. OS模块调用CMD命令有两种方式:os.popen(),os.system(). 都是用当前进程来调用. os.system是无法获取返回值的.当运行结 ...

随机推荐

  1. qq快捷打开聊天窗口的代码

    pc代码: http://wpa.qq.com/msgrd?v=3&uin=8423291&site=qq&menu=yes

  2. java字符常量

    在Java程序中经常会遇到类似于"Hello"这样地字符串,那么这种类型的字符串是Java中是如何存储,下面就说明字符串常量在内存中存储方式: Java程序在编译时会将程序中出现的 ...

  3. ASE19团队项目alpha阶段model组 scrum1 记录

    本次会议于11月1日,19时整在微软北京西二号楼13478召开,持续15分钟. 与会人员:Jiyan He, Kun Yan, Lei Chai, Linfeng Qi, Xueqing Wu, Yu ...

  4. pam_smb

    What is pam_smb? pam_smb is a PAM module/server which allows authentication of UNIX users using an N ...

  5. shell脚本中使用nohup执行命令不生效

    1 例如 !#/bin/bash nohup echo "hello world" 2 解决办法 加上 source /etc/profile 就好了 !#/bin/bash so ...

  6. C# 图像基本处理

    使用第三方:AForge实现视频采集(实现视频采集.暂停) 实现图片的常用处理功能:旋转.反色.灰度.放大.缩小.模糊.拉伸.增强.锐化.裁剪...... 实现对图片进行文字编辑......

  7. mysql服务脚本

    #!/bin/bash #*************************** #* copyleft huihui 2015-08-11 #**************************** ...

  8. pxc 5.6 忘记 root 密码

    pxc 5.6 忘记密码处理 只说思路: mysql.user 是 myisam 引擎的,pxc 只支持 innodb 引擎.其他存储引擎的更改不复制.然而,DDL(Data Definition L ...

  9. Task扩展方法取消操作

    /// <summary> /// 任务扩展,传入取消操作 /// </summary> public static class TaskExtensionDemo { //因 ...

  10. 特殊字符的过滤方法,防sql防注入代码的过滤方法

    特殊字符的过滤方法 function strFilter($str){ //特殊字符的过滤方法 $str = str_replace('`', '', $str); $str = str_replac ...