简体   繁体   中英

Getting a deployed MVC page in IIS 7.5. to run a batch file from the command line

For one of my projects I needed to integrate a .NET page with an outside call to a MATLAB process. In order to do this (and not spend any money in doing so), I created a batch file to be called by the .NET page itself (ASP.NET MVC 3, if that matters any) which basically contains one line--that to start up MATLAB and run this process.

The end of the process itself spits out information into a text file and then shuts down MATLAB. When the .NET page sees that the file has been created it grabs it and spits out some calculations based on the data found in that file. This process has been working perfectly on my local machine, and when I run it from VS 2012 (in debug mode) on the server.

The fun part comes with deploying this site. I have successfully deployed my site to the internet, and everything on it works well, except for this process. It appears to not be running at all. The directory that contains this batch file has all the necessary permissions attached to it (IUSR and IIS_IUSRS), and yet seems to not be running at all.

Can anybody please tell me how to get this batch file to run properly in a web page being hosted on IIS 7.5? And yes, I do know that this is not the best of ideas security-wise, but I just need to get this done.

EDIT: Here's the code for calling the process:

var matlabProcess = new Process {
    StartInfo = {
        FileName = "C:\\Program Files\\MATLAB\\R2012a\\bin\\WebCall.bat", 
        Arguments = string.Format("{0} {1}", seeds, weights)
    }
};

matlabProcess.Start();

The batch file contains the following:

cd\
cd progra~1\MATLAB\r2012a\bin
start matlab -nosplash -nodesktop -minimize -r WebCall(%1,%2)

EDIT: A friend of mine suggested that the reason that this is failing is because there's no handler on IIS for a batch file, and therefore IIS has no idea how to even run that file. If so, can someone then please tell me how to create a proper handler mapping so that I can see if his solution was correct?

Thanks.

64 Bit OS? If so, perhaps you have some redirection going on. If it is a 32 bit app, you should be specifying %ProgramFiles(x86)%. It's best to check and use the appropriate one so it works on either 32 or 64 bit.

Are you executing from a UNC location (requires considerations on some newer OS's and may not be possible on Win 8 and 2012 Server)?

Put this as the first statement in the bat file:

echo.CD=%cd% & pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM