Trouble executing Perl script in C# Web Applicatio

2019-07-27 11:56发布

问题:

Simply, I am having issues with executing a Perl script with input parameters within a C# Web Application. I have no problem executing the code from a Console application, but within my web app, I receive no response.

The code I am using is:

ProcessStartInfo cmdStartInfo = new ProcessStartInfo();
cmdStartInfo.FileName = "C:\gnu\perl.exe";
cmdStartInfo.Arguments = "run.pl --day=1 --format=2";
cmdStartInfo.RedirectStandardOutput = true;
cmdStartInfo.RedirectStandardError = true;
cmdStartInfo.RedirectStandardInput = true;
cmdStartInfo.UseShellExecute = false;
cmdStartInfo.CreateNoWindow = true;
cmdStartInfo.WorkingDirectory = TEMP_DIRECTORY;

Process cmdProcess = new Process();
cmdProcess.StartInfo = cmdStartInfo;
cmdProcess.OutputDataReceived += cmd_DataReceived;
cmdProcess.EnableRaisingEvents = true;

// Start
cmdProcess.Start();
cmdProcess.WaitForExit();

and

static void cmd_DataReceived(object sender, DataReceivedEventArgs e)
{
    // Breakpoint to DEBUG here
    string result = e.Data;
}

I am using IIS 7. I wonder if it is an issue in there? I am using Identity Impersonate and Windows Authentication.

回答1:

This ended up being a Permissions issue. I had to grant permissions on the directory containing the script to be executed using the Perl command.

For example, the permissions would be given to the directory, dir1 in this example:

perl.exe dir1/script.pl

Originally I only granted permissions on the folder that contained the perl.exe file, which did not resolve the issue.



标签: c# perl iis iis-7