Executing a shell command in a web service RRS feed

  • Question

  • User-588761007 posted


    I've just started with ASP.net, but have been doing web work and OO programming for a while. I'm working off IIS7 on Windows Server 2008.

    I want to execute a program on the server-side using a web service. This program reads in some text files, runs some code and writes the results to file. I'm trying to launch the (GAMS) program using a batch file containing the necessary shell command. Here's the contents of the .bat file:

    gams c:\gams\stage1.gms idir C:\GAMS\inputs Wdir=C:\GAMS

    When I launch the .bat file in windows a command window flashes up and the results file is written to disk. Excellent.

    So, now I tried to execute this batch file using a simple ASP.net Web Service. Here's the code:

    <%@ WebService Language="C#" class="HelloWorld" Debug="true"%>
    using System.Web.Services;
    [WebService(Namespace = "http://tempuri.org/")]
    public class HelloWorld : WebService 
    	public string ExecuteTest() 
    		System.Diagnostics.Process proc = new System.Diagnostics.Process();
    		return "bat file executed"; 

    When I run this in a browser, I get the xml response:

      <?xml version="1.0" encoding="utf-8" ?> 
      <string xmlns="http://tempuri.org/">bat file executed</string> 

    However, the GAMS program either never executes or something goes wrong as the output of the GAMS program is never written to disk. I presumed there was a permissions issue but I've given full control permissions to the NETWORK SERVICE user on the affected directories and I'm not seeing ACCESS DENIED messages in Process Monitor.

    How do I know if the program executed at all? I believe that the program would be running on an invisible desktop so I can't see anything. I'm sure I probably need more code as well. I tried to add proc.WaitForEnd() for example, but that caused an error.


    Any ideas?


    Thanks for your help

    Tuesday, November 17, 2009 4:34 PM