我有一个实现 Quartz.NET 调度的 Windows 服务,它从 XML 文件中读取调度的作业信息,解析它以运行 cmd 行,并使用解析的参数创建一个调度的作业。
我目前正在使用 PHP 命令行脚本来测试调度程序的命令行执行,它似乎可以很好地启动作业,它们甚至成功完成,在 eventLog 中显示脚本输出......
问题是每次运行时,都会显示一个带有错误的警告弹出窗口:
“PHP 启动:无法加载动态库 'C:\php5\php_mssql.dll' - 访问被拒绝”
如果我对此警告响应 OK,则脚本似乎运行良好,但如果它仍然在屏幕上,则进一步计划的 PHP 脚本将运行完成,但输出为空(我假设在它之前运行的暂停作业阻碍了它。 )...
如何以编程方式防止访问被拒绝消息?
运行解析后的 CMD 行的 Quartz.NET Job Execution 脚本如下:
public void Execute(JobExecutionContext context)
{
EventLog eventLog = new EventLog();
eventLog.Source = "SchedulerServiceSource";
eventLog.Log = "SchedulerService";
JobDataMap dataMap = context.MergedJobDataMap; // contanis information for this job parsed from the XML file.
String jobName = dataMap.GetString("name");
String execute = dataMap.GetString("execute");
String args = dataMap.GetString("arguments");
//String LogMsg = "JobRunner Executing=============\n"; // Written to event log after job execution
//LogMsg += "JobName: " + jobName + "\n";
//LogMsg += "Executing: " + execute + "\n";
// eventLog.WriteEntry(LogMsg); // Write the job's details to the log
try
{
Process p = new Process(); // Start the child process.
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = execute;
p.StartInfo.Arguments = args;
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
String output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
eventLog.WriteEntry(jobName + "\nexecuted:\n---------------\n" + execute + " " + args + "\n---------------\nRESULTS:\n===============\n" + output + "\n===============");
}
catch (Exception ex)
{
eventLog.WriteEntry(jobName + "\nattempted to execute:\n---------------\n" + execute + " " + args + "\n---------------\n...FAILED:\n===============\n" + ex.Message + "\n===============", EventLogEntryType.Error);
}
}
提前谢谢大家!
编辑:我正在运行的 php 脚本是一个简单的 HELLO WORLD,它不与数据库交互,但我有一种感觉,如果我确实运行了一个使用 DB 功能的脚本,它会由于访问被拒绝消息而失败......这个也是不能接受的,这个项目我必须能满负荷使用PHP!
EDIT2:我使用 Windows LocalService 帐户安装了该服务。