简体   繁体   中英

Running perl script from asp.net application deployed on IIS 7.5

I have a very urgent requirement. I have a ASP.net application on framework 4.0 done in MVC architecture. In the application I am calling a Perl script to copy data from MySQL to SQL Server 2010 in the backend. When I run the application from Visual Studio 2010, the Perl script runs successfully and the data is copied. But when I deploy the same application on IIS 7.5, it does not show any change or the Perl scipt does not run. I tried printing each step of the code and found all the paths are coming correct. The perl script is to be run via a batch file.

Below is the code to start the process which runs a batch file which in turn runs the Perl script:

string strPath = string.Empty;
string strDirectory = string.Empty;
try {   
    strPath = "/k " + ConfigurationManager.AppSettings["UploadTLInfo"];//Path of the batch file comes from here 
    strDirectory = ConfigurationManager.AppSettings["WorkingDirectory"];
    ProcessStartInfo psi = new ProcessStartInfo("cmd.exe",strPath);
    psi.UseShellExecute = false;
    psi.WorkingDirectory = strDirectory;
    //psi.CreateNoWindow = true;
    //psi.WindowStyle = ProcessWindowStyle.Hidden;
    Process p = new Process();
    p.StartInfo = psi;
    p.Start();                
} catch (Exception ex) {
    throw ex;
}

Most probably, your issue will be related to user permissions - when you run from VS, you are probably using ASP.NET Dev server and it users current user's credentials while when you run from IIS, it would be using NETWORK_SERVICE (or similar system users) that may have limited permissions causing the issue. Another (but unlikely) issue can be that batch file and/or pearl might be relying on some environment variable that are not defined at machine level etc.

One of the solution would be to run the process impersonating another user that has specific permission and/or environment ( see this to run process as another user ).

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