5

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.

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the possible answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.