惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 感觉De味道

CRC16_Check 源代码类修改版 HI baidu~~~~~~开通了~~~ [转] js 选时间的控件 - 感觉De味道 自我复制的简单实现(C#) VS2005 中比较有用的快捷键 C#让windows程序只运行一次 [转] - 感觉De味道 - 博客园 只允许一个进程运行的实例 网址大全[收集网上大部份好的开源网] C#模拟MSN窗体抖动 javascript 常用小技巧 - 感觉De味道 - 博客园 衔接UI线程和管理后台工作线程的类(多线程、异步调用)[转] 关于线程问题 [转] 扫雷高手版出台 (本站原创) 写了一个操作XML文件的类 用C#捕捉键盘和鼠标 类型转换(本站原创) 一个简单的C#托盘程序(本站原创) 232串口通信程序刚完成(本站原创) 木马代码
使用C#调用外部命令 - 感觉De味道 - 博客园
感觉De味道 · 2008-01-25 · via 博客园 - 感觉De味道

        Process Main_P = new Process();
  Main_P.StartInfo.FileName = @"C:\\rmc.exe";//运行的文件
  Main_P.StartInfo.Arguments = @"-screefull";//参数
  Main_P.StartInfo.UseShellExecute = true;
  Main_P.Start();

<转>
使用C#调用外部命令

首先,我们用使用Process类,来创建独立的进程,导入System.Diagnostics,
uing System.Diagnostics;
实例一个Process类,启动一个独立进程
Process p = new Process();
Process类有一个StartInfo属性,这个是ProcessStartInfo类,包括了一些属性和方法。
下面我们用到了他的几个属性:
设定程序名        p.StartInfo.FileName = "cmd.exe";
关闭Shell的使用 p.StartInfo.UseShellExecute = false;
重定向标准输入   p.StartInfo.RedirectStandardInput = true;
重定向标准输出   p.StartInfo.RedirectStandardOutput = true;
重定向错误输出   p.StartInfo.RedirectStandardError = true;
设置不显示窗口   p.StartInfo.CreateNoWindow = true;
上面几个属性的设置是比较关键的一步。

既然都设置好了那就启动进程吧
p.Start();
输入要执行的命令,这里就是ping了,
p.StandardInput.WriteLine("ping -t  192.192.132.229");
p.StandardInput.WriteLine("exit");
从输出流获取命令执行结果,
string strRst = p.StandardOutput.ReadToEnd();
////////////////////////////////////////////////////////////////////////////