我想在C#asp.net(mvc)中运行.exe或bat文件

时间:2017-11-21 09:38:38

标签: javascript c# html asp.net-mvc

下面是我使用的不同代码,但我需要执行ETL或批处理文件,通过视图页面给按钮dashbord链接,但我无法执行或运行文件 请建议我同样

public ActionResult RunETL(){
    try
    {
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo = new System.Diagnostics.ProcessStartInfo(@"D:\Jobs\Execute");
        p.Start();


        //Process p = new Process();
        //// Redirect the output stream of the child process.
        //p.StartInfo.UseShellExecute = false;
        //p.StartInfo.RedirectStandardOutput = true;
        ////p.StartInfo.FileName = @"D:\Jobs\Execute";

        //p.Start();
        //// Do not wait for the child process to exit before
        //// reading to the end of its redirected stream.
        //p.WaitForExit();
        //// Read the output stream first and then wait.
        //string output = p.StandardOutput.ReadToEnd();
        //p.WaitForExit();
        //Response.Write("Done");
        ////ViewBag.Result = "ETL Running";
    }
    catch (Exception ex)
    {

        //ViewBag.Result = ex.Message;

    }

    return RedirectToAction("Home");
}

1 个答案:

答案 0 :(得分:0)

查看用于运行Web应用程序的应用程序池标识。

它应该在批处理文件的位置上有一个执行权限。