无法在C#Web应用程序中执行Perl脚本 [英] Trouble executing Perl script in C# Web Application
问题描述
简而言之,我在执行带有C#Web应用程序中输入参数的Perl脚本时遇到问题.我从控制台应用程序执行代码没有问题,但是在我的Web应用程序中,没有收到任何响应.
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.
我正在使用的代码是:
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();
和
static void cmd_DataReceived(object sender, DataReceivedEventArgs e)
{
// Breakpoint to DEBUG here
string result = e.Data;
}
我正在使用IIS7.我想知道那里是否存在问题?我正在使用身份模拟和Windows身份验证.
I am using IIS 7. I wonder if it is an issue in there? I am using Identity Impersonate and Windows Authentication.
推荐答案
这最终是一个权限问题.我必须授予包含要使用Perl命令执行的脚本的目录的权限.
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.
例如,权限将授予目录,在此示例中为dir1:
For example, the permissions would be given to the directory, dir1 in this example:
perl.exe dir1/script.pl
最初,我只授予了包含perl.exe文件的文件夹的权限,这不能解决问题.
Originally I only granted permissions on the folder that contained the perl.exe file, which did not resolve the issue.
这篇关于无法在C#Web应用程序中执行Perl脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!