执行流程任务上没有可用的选项可以在失败时重定向输出并将其重新记录到日志中。
为了实现这一点,您需要:
- 定义一个变量来捕获输出
- 在执行进程任务的 StandardOutputVariable 选项中进行设置
- 在该任务的事件处理程序下,创建一个“OnTaskFailed”事件处理程序并使用脚本任务返回输出
Example:
String variable called "User::exe_output" which is then added the StandardOutputVariable on the Execute Process Task:
The 文档 https://learn.microsoft.com/en-us/sql/integration-services/control-flow/execute-process-task?view=sql-server-2017 states:
标准输出变量选择一个变量来捕获输出
过程,或单击以创建新变量。
然后在事件处理程序下:
- 在执行流程任务上添加“OnTaskFailed”事件
- 添加脚本任务
打开脚本任务并将“User::exe_output”变量添加为 ReadOnlyVaraibles:
编辑脚本并添加以下代码:
public void Main()
{
//Just assigning the exe_output to a local variable
string exe_error = Dts.Variables["User::exe_output"].Value.ToString();
//Checking it its blank
if (exe_error != "")
{
//This brings back out whatever was captured in the output of the execute process task.
//Depending on how you want it logged, warning or an error, either one will log the output.
//Dts.Events.FireError(-1, "Execute Process Task Error", exe_error, String.Empty, 0);
Dts.Events.FireWarning(-1, "Execute Process Task Error", exe_error, String.Empty, 0);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
然后,当流程运行并失败时,您仍然会收到原始消息,但现在您还可以获得从执行流程任务的输出中捕获的内容:
在我的示例中,我只是尝试复制一个不存在的文件。