I was wondering if it was possible to run a command line function on the server through a mvc web app.
To clarify myself:
A user uploads a couple of files to the server through the mvc web app. He/she then presses a button
and the server runs a command line application.
Is this possible?
Thank you in advance
NB: The server is Windows 2008.
Yes. Assuming you have a command line app (i.e. you own console app) that requires no user interaction you can try the following within your controller method.
Process serverSideProcess = new Process();
serverSideProcess.StartInfo.FileName = @"C:\pathToTheExe";
serverSideProcess.StartInfo.Arguments = "arg1 arg2 arg3";
serverSideProcess.EnableRaisingEvents = true;
serverSideProcess.StartInfo.UseShellExecute = true;
serverSideProcess.Start();
One thing to take note of the Identity of the user account that will execute this process. By default, this should execute server side using the AppPool's credentials. This may be an issue if you need to access network resources. One way to simply overcome this is to let AppPool run under a user account that has been granted access to these resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With