C#执行批处理命令
来源:互联网 发布:淘宝0.1元商品 编辑:程序博客网 时间:2024/05/16 01:23
using System.Diagnostics ;
using System.IO;
private void btnRun_Click(object sender, EventArgs e)
{
txtResult.Text = "";
processCommand("Ping.exe", this.txtAddress.Text);
processCommand("Ping.exe", this.txtAddress.Text);
}
public void processCommand(string commandName, string argument)
{
ProcessStartInfo start = new ProcessStartInfo(commandName);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
//如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
start.WorkingDirectory = "d:\\360Downloads\\";
start.Arguments = argument;//设置命令参数
start.CreateNoWindow = true;//不显示dos命令行窗口
start.RedirectStandardOutput = true;//
start.RedirectStandardInput = true;//
start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
txtResult.AppendText(start.WorkingDirectory + "\n");
Process p = Process.Start(start);
StreamReader reader = p.StandardOutput;//截取输出流
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)
{
txtResult.AppendText(line + "\n");
line = reader.ReadLine();
}
p.WaitForExit();//等待程序执行完退出进程
p.Close();//关闭进程
reader.Close();//关闭流
}
=================================================================================
private void button10_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "bat 文件 (*.bat)|*.bat|所有文件 (*.*)|*.*";
openFileDialog1.DefaultExt = "mp3";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Process ps = new Process();
ps.StartInfo.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
ps.StartInfo.FileName = openFileDialog1.FileName;
ps.StartInfo.CreateNoWindow = true;//不显示dos命令行窗口
ps.Start();
ps.Close();//关闭进程
}
}
- C#执行批处理命令
- C# 动态执行批处理命令
- C# 动态执行批处理命令
- C# 执行dos命令及批处理
- psftp 执行批处理命令
- c#执行批处理
- C#执行batwindows批处理
- 标准c执行批处理命令
- 使用C#创建WindowsService(Windows服务):定期执行Dos命令或Bat(批处理)文件
- 批处理技巧 批处理获取上一条命令的执行结果
- 批处理技巧 批处理获取上一条命令的执行结果
- DOS下通过批处理执行sql命令
- 用批处理来自动执行FTP命令
- java执行批处理命令 获取返回 数据
- Postgresql通过批处理命令执行sql文件
- bat批处理循环执行adb命令
- c#执行外部批处理(bat)文件
- C# 执行外部批处理(bat)文件
- expat介绍文档翻译
- 防止滑盖事件造成crash
- 用Shell脚本实现自动从NewSmth.net的MyPhoto版下载照片
- Android 下log的使用总结
- 05 trigger the checkbox column in datagridview
- C#执行批处理命令
- C++ vector容器类型
- squid缓存批量更新
- Access不能读取记录;在'MSysObjects' 上没有读取数据权
- 维护CentOS6.2下的一些常用脚本之二
- 关于Android用户定位获取location值为null的解决方法
- 关于TCP封包、粘包、半包
- violate
- C语言struct和union结合使用,空间最小