开发者

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 t开发者_开发问答he 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜