运行命令行code编程 [英] Run command line code programatically

查看:94
本文介绍了运行命令行code编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个code运行在Windows命令PROMT ..
但我需要这种编程方式使用C#code,请帮助完成


  

C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319> ASPNET_REGIIS.EXE -pdf连接
  琴弦C:\\用户\\ XXX \\桌面\\连接字符串\\ DNN



解决方案

您可以使用的 的Process.Start 方式:

 的Process.Start(
    @C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\ ASPNET_REGIIS.EXE
    @ - PDF格式连接字符串C:\\用户\\ XXX \\桌面\\连接字符串\\ DNN
);

如果你想在外壳更多的控制权,并能够捕捉到例如标准输出和错误,你可以使用的 过载 采取的ProcessStartInfo

  VAR PSI =新的ProcessStartInfo(@C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\ ASPNET_REGIIS.EXE)
{
    参数= @ - PDF格式连接字符串C:\\用户\\ XXX \\桌面\\连接字符串\\ DNN
    UseShellExecute =假,
    CreateNoWindow =真
};
的Process.Start(PSI);

I'm using this code run in windows command promt.. But I need this done programatically using c# code please help

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -pdf "connection Strings" "C:\Users\XXX\Desktop\connection string\DNN"

解决方案

You may use the Process.Start method:

Process.Start(
    @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe",
    @"-pdf ""connection Strings"" ""C:\Users\XXX\Desktop\connection string\DNN"""
);

or if you want more control over the shell and be able to capture for example the standard output and error you could use the overload taking a ProcessStartInfo:

var psi = new ProcessStartInfo(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe")
{
    Arguments = @"-pdf ""connection Strings"" ""C:\Users\XXX\Desktop\connection string\DNN""",
    UseShellExecute = false,
    CreateNoWindow = true
};
Process.Start(psi);

这篇关于运行命令行code编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆