C# 如何执行bat文件 传参数

C# 如何执行bat文件 传参数

分类: C# basic 2011-04-25 18:55 3972人阅读 评论(0) 收藏 举报

c#stringpathoutput

[c-sharp] view plaincopy

  1. Process p = new Process();
  2. string path = ...;//bat路径
  3. ProcessStartInfo  pi= new ProcessStartInfo(path, ...);//第二个参数为传入的参数,string类型以空格分隔各个参数
  4. pi.UseShellExecute = false;
  5. pi.RedirectStandardOutput = true;
  6. p.StartInfo = pi;
  7. p.Start();
  8. p.WaitForExit();
  9. string output = p.StandardOutput.ReadToEnd();

bat文件的内容为

[vb] view plaincopy

  1. echo %1  %2  %3
  2. pause
时间: 2024-12-21 10:23:57

C# 如何执行bat文件 传参数的相关文章

ocx怎么得到classid,与动态执行 bat 文件

1.注册ocx控件: Regsvr32 [PATH]\xxx.ocx2.利用Regedit.exe注册表编辑器,在编辑器的查找里直接输入 .OCX文件名进行查找,找到:“HKEY_CLASSES_ROOT\CLSID\{xxxxxxxxxxxxxxxxxxxxxxxxxxx}”主键后,再利用注册表编辑器菜单上-[注册表]-[导出注册表文件]-然后在文件选择窗里输入导出的注册表文件名 public sealed class COMUtils { /// <summary> /// 检查指定的 C

给js文件传参数

给js文件传参数 一.利用全局变量 这是最简单的一种方式,比如Google Adsense: <script type="text/javascript"> google_ad_client ='pub-3741595817388494'; </script> <script type="text/javascript" src="http://pagead2. googlesyndication.com/pagead/sho

win7计划任务执行BAT文件问题

今天下午做了一个调用java 可执行jar的程序,想通过win7的计划任务来调用 批处理命令: java -jar BIDropSyc.jar    或者 javaw -jar BIDropSyc.jar 但添加以后发现win7没有调用jar程序,单独点击批处理文件能执行.发现问题是由于没有添加批处理文件所在路径.在如下图框中添加上即可. win7计划任务执行BAT文件问题,布布扣,bubuko.com

Javascript中使用WScript.Shell对象执行.bat文件和cmd命令

Javascript中使用WScript.Shell对象执行.bat文件和cmd命令 http://www.cnblogs.com/ZHF/p/3328439.html WScript.Shell(Windows Script Host Runtime Library)是一个对象,对应的文件是C:/WINDOWS/system32/wshom.ocx,Wscript.shell是服务器系统会用到的一种组件.shell 就是“壳”的意思,这个对象可以执行操作系统外壳常用的操作,比如运行程序.读写注

使用java对执行命令行 或 执行bat文件

public class Hellotianhao { public static void main(String[] args) throws Exception{ System.out.println("hello tianhao"); Runtime.getRuntime().exec("cmd /k mkdir d:\\xutianhao"); } } 运行结果是在d盘新建了一个名为xutianhao的文件夹 java执行bat文件  bat文件书写注意在

Js使用WScript.Shell对象执行.bat文件和cmd命令

http://www.jb51.net/article/58669.htm WScript.Shell(Windows Script Host Runtime Library)是一个对象,对应的文件是C:/WINDOWS/system32/wshom.ocx,Wscript.shell是服务器系统会用到的一种组件.shell 就是“壳”的意思,这个对象可以执行操作系统外壳常用的操作,比如运行程序.读写注册表.环境变量等.这个对象通常被用在VB或VBS编程中. 安装WScript.Shell对象:

C# 执行bat文件 批处理 - 实现应用程序开机启动功能

最近在做一个项目(平台 .net 4.0 winform)的时候,客户要求软件能提供开机启动的设置选项 开始的时候,实现方法如下: public class Boot { //写入注册表 public static void bootFromBoot(string ExeName, string ExePath) { RegistryKey rKey = Registry.LocalMachine; RegistryKey autoRun = rKey.CreateSubKey(@"SOFTWA

JavaScript执行bat文件清理浏览器缓存

function exec() { window.onerror = function (err) { if (err.indexOf('utomation') != -1) { alert('命令已被用禁止!'); return true; } else{ return false; } }; var wsh = new ActiveXObject('WScript.Shell'); if (wsh){ wsh.run("C:/Users/Vision/Desktop/1111.sql&quo

C# 执行bat文件

private void RunBat(string batPath) { Process pro = new Process(); FileInfo file = new FileInfo(batPath); pro.StartInfo.WorkingDirectory = file.Directory.FullName; pro.StartInfo.FileName = batPath; pro.StartInfo.CreateNoWindow = false; pro.Start(); p