如何执行其中可执行路径来自用户变量的流程任务 [英] How to execute a Process Task where the Executable path comes from a user Variable

查看:36
本文介绍了如何执行其中可执行路径来自用户变量的流程任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含进程任务的 SSIS 包.流程任务需要执行批处理文件.批处理文件的位置因环境(开发、生产)而异.

I have an SSIS package that includes a Process Task. The process task needs to execute batch file. The location of the batch file varies depending on the environment (dev, production).

如何将 Process Task 对象的 Executable 属性的 tghe 值动态设置为用户变量?

How do I dynamically set tghe value of the Executable property of the Process Task object to a user variable?

推荐答案

我认为您需要创建一个变量,该变量接受文件夹路径和可执行文件名以作为表达式进行计算.然后,您需要将此作为表达式求值的变量分配给 Execute Process Task 的 Executable 属性.此外,您需要在设计时拥有有效的可执行路径.

I think that you need to create a variable that takes in the folder path and the executable file name to evaluate as an expression. You then need to assign this variable that evaluates as expression to the Executable property of the Execute Process Task. Also, you need to have a valid executable path during design time.

这是一个粗略的分步示例,展示了如何将变量传递给 Execute Process Task 的 Executable 属性.该示例是使用 SSIS 2008 R2 创建的,还使用三个 .bat 文件来说明功能.即使示例在 SSIS 2008 R2 中,逻辑也应适用于 SSIS 2005.

This is a crude step-by-step example that shows how you can pass a variable to the Executable property of Execute Process Task. The example was created using SSIS 2008 R2 and also uses three .bat files to illustrate the functionality. Even though the example is in SSIS 2008 R2, the logic should be applicable to SSIS 2005.

创建三个 .bat 文件,即 Process_0.bat、Process_1.bat 和 Process_2.bat.请参阅屏幕截图 #1.使用 echo 命令填充它们,如屏幕截图 #2 - #4 中所示.

Create three .bat files namely Process_0.bat, Process_1.bat and Process_2.bat. Refer screenshot #1. Populate them with echo commands as shown in screenshots #2 - #4.

创建一个 SSIS 包.我在开头以 YYYYMMDD_hhmm 格式命名包,然后是 SO 代表堆栈溢出,然后是 SO 问题 ID,最后是描述.这是让我以后轻松参考.请参阅屏幕截图#5.

Create an SSIS package. I have named the package in the format YYYYMMDD_hhmm in the beginning followed by SO stands for Stack Overflow, followed by the SO question id, and finally a description. This is for me to easily refer this back later. Refer screenshot #5.

创建以下变量:参考屏幕截图#6.

Create the following variables: Refer screenshot #6.

  • ExecutableFileName - 这个变量是字符串类型.它将包含可执行文件名.

  • ExecutableFileName - This variable is of type string. It will contain the executable file name.

ExecutableFolder - 这个变量是字符串类型.它将包含可执行文件的文件夹路径.

ExecutableFolder - This variable is of type string. It will contain the executable file' folder path.

ExecutableFilePath - 这个变量是字符串类型.不要为此变量键入任何值.这将是一个组合变量 ExecutableFolder 和 ExecutableFileName 以生成完整文件路径的表达式.请参阅屏幕截图 #7.选择变量并按 F4 打开属性窗口.将 EvaluateAsExpression 设置为 True 并将表达式设置为 @[User::ExecutableFolder] + @[User::ExecutableFileName]

ExecutableFilePath - This variable is of type string. Do not key in any value for this variable. This will be an expression that combines the variables ExecutableFolder and ExecutableFileName to generate the full file path. Refer screenshot #7. Select the variable and press F4 to open the properties window. Set EvaluateAsExpression to True and set the Expression to @[User::ExecutableFolder] + @[User::ExecutableFileName]

ExecutableOutput - 这个变量是字符串类型.它将存储可执行文件的输出值.在这种情况下,该值由 .bat 文件回显.

ExecutableOutput - This variable is of type string. It will store the executable's output value. In this case, the value echoed by the .bat files.

在包的控制流路径上,放置执行流程任务和脚本任务,如屏幕截图 #8 所示.

On the package's control flow path, place Execute Process Task and a Script Task as shown in screenshot #8.

配置执行流程任务,如屏幕截图 #9 - #11 所示.在Task的Process部分,需要指定一个Executable路径进行初始配置.此外,指定 StandardOutputVariable(这是针对此示例的).在 Expressions 部分,通过指定变量 @[User::ExecutablePath]

Configure the Execute Process Task as shown in screenshot #9 - #11. On the Process section of the Task, you need to specify an Executable path for initial configuration. Also, specify the StandardOutputVariable (this is for this example). On the Expressions section, override the Executable path by specifying the variable @[User::ExecutablePath]

在脚本任务中,替换屏幕截图中的 Main 方法#12 - #13.

On the Script Task, replace the Main method as shown in screenshots #12 - #13.

执行包.您应该获得如屏幕截图 #14 所示的输出.它显示了 .bat 文件 Process_0.bat 与输出 "Process 0" 一起执行.

Execute the package. You should get the output as shown in screenshot #14. It shows the .bat file Process_0.bat was executed with the output "Process 0".

现在,将变量 ExecutableFileName 的值更改为 Process_1.bat.请勿进行任何其他更改.执行包.您应该获得如屏幕截图 #15 - #16 中所示的输出.它显示了 .bat 文件 Process_1.bat 与输出 "Process 1" 一起执行.

Now, change the value of the variable ExecutableFileName to Process_1.bat. Do not make any other changes. Execute the package. You should get the output as shown in screenshots #15 - #16. It shows the .bat file Process_1.bat was executed with the output "Process 1".

现在,将变量 ExecutableFileName 的值更改为 Process_2.bat.请勿进行任何其他更改.执行包.您应该获得如屏幕截图 #17 - #18 中所示的输出.它显示了 .bat 文件 Process_2.bat 与输出 "Process 2" 一起执行.

Now, change the value of the variable ExecutableFileName to Process_2.bat. Do not make any other changes. Execute the package. You should get the output as shown in screenshots #17 - #18. It shows the .bat file Process_2.bat was executed with the output "Process 2".

希望有所帮助.

屏幕截图:

#1:

#2:

#3:

#4:

#5:

#6:

#7:

#8:

#9:

#10:

#11:

#12:

#13:

#14:

#15:

#16:

#17:

#18:

这篇关于如何执行其中可执行路径来自用户变量的流程任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆