简体   繁体   中英

I want to run .exe or bat file in C# asp.net (mvc)

Below are different code I have used but I need to execute ETL or batch file gave link to button dashbord via view page but I couldn't execute or run file please suggest me on same

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");
}

have a Look at the Application Pool Identity that's used to run your web app.

it should have a Execute Right on the location of the batch file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM