C# 和Dos窗口的交互
class Program
{
static void Main(string[] args)
{
Console.WriteLine("begin");
var file = @"D:\book\RR\RR.csproj";
Console.WriteLine("hello world");
var dosLine = $"upgrade-assistant upgrade {file}";
Process ipconfigProcess = new Process();
// Indicate that we want to execute ipconfig
ipconfigProcess.StartInfo.FileName = "upgrade-assistant";
ipconfigProcess.StartInfo.Arguments = $"upgrade {file}";
// Indicate that we want to read the command line output
ipconfigProcess.StartInfo.RedirectStandardOutput = true;
ipconfigProcess.StartInfo.UseShellExecute = false;
ipconfigProcess.StartInfo.RedirectStandardInput = true;
ipconfigProcess.OutputDataReceived += IpconfigProcess_OutputDataReceived;
// Start the process to execute ipconfig
ipconfigProcess.Start();
// Get a StreamReader to read from the standard output of
// the ipconfig process
StreamReader reader = ipconfigProcess.StandardOutput;
var input = ipconfigProcess.StandardInput;
// Perform reading and writing of standard output to Console
String line;
string sumLine = "";
while ((line = reader.ReadLine()) != null)
{
sumLine += line + "\r\n";
Console.WriteLine(line);
input.WriteLine(1);
} // end while
Console.ReadKey();
Console.WriteLine("end");
Console.ReadKey();
}
private static void IpconfigProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}
}
相关文章
- C# 系统应用之调用SDelete程序粉碎文件及基础原理知识
- C#子线程中更新ui-----c# 多线程多文件批量下载
- C# WinForm登录窗口代码
- C#.NET常见问题(FAQ)-如何让TabControl可以动态增加或删除
- C#几个经常用到的字符串截取
- C#模板方法模式
- C# URL带中文参数的解决办法
- C#中三种定时器对象的比较
- C# 下载带进度条代码(普通进度条)
- C# 如何识别一个字符串是否Json格式
- Atitit. c# 语法新特性 c#2.0 3.0 4.0 4.5 5.0 6.0 attilax总结 1. 版本历史1 1.1. C# 1.0-纯粹的面向对象2 1.2. C# 2.0
- C#-MaximumSIze,MinimumSize,窗口默认大小范围---ShinePans
- C# wpf 实现窗口靠近屏幕边缘自动吸附
- c# volatile 关键字的拾遗补漏
- C# 不是异步的方法中获取异步的结果
- [C#]c#中数据的同步加锁机制 的几种方法