Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server side command line

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.

like image 292
Cobalt Avatar asked Apr 08 '11 08:04

Cobalt


1 Answers

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.

like image 179
Ahmad Avatar answered Sep 18 '22 01:09

Ahmad