运行命令行code编程 [英] Run command line code programatically
问题描述
我使用这个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 aProcessStartInfo
: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屋!