0

Hi fellow software developers

So I need to start a CMD process in my .NET MVC web project. This is my function that I pass the command I need to call:

private void ExecuteCommandSync(string command)
        {
            System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
            // Hide the CMD window:
            procStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            // The following commands are needed to redirect the standard output.
            procStartInfo.UseShellExecute = true;
            // Now we create a process, assign its ProcessStartInfo and start it
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            proc.WaitForExit();
        }

The command calls a program that starts a linear programming framework that solves a problem which takes 20 seconds to finish.

The problem is that nothing happens when this function is called! It works fine outside the IIS, but not in IIS. The IIS web server runs on a Windows Server 2012. My web project is called from outside of our local network, where the web server is running, does some work, calls my synchronous method and waits for it to finish and ends by returning the result of the call as a JSON object.

This question suggests that it might have something with user privileges. In the Application Pools for the web project in Advanced Settings -> Identity I have tried to change from ApplicaitonPoolIdentity to Local System (which has high privileges) but no luck (as explained here).

Does anyone have any suggestions to how I can solve this problem? Any advice would be greatly appreciated.

Community
  • 1
  • 1
David
  • 89
  • 1
  • 15
  • 1
    You don't get any errors? How are you debugging it? – Simen S Feb 01 '16 at 21:13
  • It's really hard to debug this problem! I'm not really getting any errors. – David Feb 01 '16 at 21:16
  • You could try to do what's suggested here: http://stackoverflow.com/questions/4624113/start-a-net-process-as-a-different-user – Simen S Feb 01 '16 at 21:17
  • What happens sometimes when you call windows applications from within IIS is that the thread is blocked by a forms dialog containing an error message (which is never going to be displayed within IIS) – Simen S Feb 01 '16 at 21:18
  • 20 seconds might be causing a timeout either in IIS (request takes too long to process), or in the client (browser got bored and aborted the connection). – Sam Axe Feb 01 '16 at 22:24
  • @SamAxe I can conclude that a timeout does not happen as the whole thing takes under 1 second where it should take 20 seconds. – David Feb 02 '16 at 08:29

1 Answers1

0

you must run project pool under user have privilege's to execute exec.

Realbitt
  • 388
  • 6
  • 18