使用C#以编程方式运行命令行代码 [英] Run command line code programmatically using C#
本文介绍了使用C#以编程方式运行命令行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码在Windows命令提示符下运行. 但是我需要使用C#代码以编程方式完成
I'm using this code run in windows command prompt.. But I need this done programmatically using C# code
C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319> aspnet_regiis.exe -pdf连接 字符串" C:\ Users \ XXX \ Desktop \ connection string \ DNN"
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);
这篇关于使用C#以编程方式运行命令行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文