asp.net执行cmd命令(包括第三方应用的命令行)

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strpath = MapPath(@"~\App\AcmeCADConverter");//放在站点目录不用设置过多的权限
string stroutpath = MapPath(@"~\Out");     //输出目录也放在站点下面
string strinpath = MapPath(@"~\Infiles\");   //文件也放在站点目录下面
string commandText = strpath + @"\AcmeCADConverter /r /e /w 1280 /h 800 /f 2 /d " + stroutpath + " " + strinpath + "test.dwg";  //要执行的cmd命令
p.Start();
p.StandardInput.WriteLine(commandText);
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();

Response.Write("执行完成");
View Code

 

为了执行方便,我们把所有文件都放在站点目录下,这样不需要设置过多的权限

 

 

https://files.cnblogs.com/techMichaelLee/WebTest.rar

posted @ 2013-11-03 10:32  LetGo  阅读(723)  评论(0编辑  收藏  举报