我如何使用C#运行命令提示符命令?可以说我想按顺序运行这些命令:cd F:/File/File2/...FileX/ipconfigping google.com或类似的东西…有人可以使用此方法:void runCommands(String[] commands) {//method guts.....

我如何使用C#运行命令提示符命令?
可以说我想按顺序运行这些命令:
cd F:/File/File2/...FileX/
ipconfig
ping google.com
或类似的东西…有人可以使用此方法:
void runCommands(String[] commands)
{
//method guts...
}
这样您的输入是一系列字符串命令(例如[“ ipconfig”,“ ping 192.168.192.168”,“ ping google.com”,“ nslookup facebook.com”),应在特定命令的单个命令提示符下执行将它们放入数组的顺序.谢谢.
解决方法:
that should be executed on a single command prompt in the specific
sequence in which they are put in the array
您可以在bat文件中编写命令序列,然后如下运行.
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "YOURBATCHFILE.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Reference
织梦狗教程
本文标题为:如何使用C#轻松运行Shell命令?


基础教程推荐
猜你喜欢
- UnityShader3实现彩光效果 2023-01-16
- c# – 在数据库的控制台窗口中显示数据 2023-11-10
- C#多线程之线程池(ThreadPool) 2023-05-31
- C#用委托BeginInvoke做异步线程 2023-01-11
- 基于C#实现的轻量级多线程队列图文详解 2023-01-27
- Unity3D使用GL实现图案解锁功能 2023-01-16
- C# Socket通信的实现(同时监听多客户端) 2023-04-14
- c#计算某段代码的执行时间实例方法 2023-01-16
- 详解C#多线程编程之进程与线程 2023-03-03
- C#中序列化实现深拷贝,实现DataGridView初始化刷新的方法 2022-10-28