I have created a package which takes a variable from batch file and uses it for execution.
I am sending it from batch file as:
Exit %Output%
And set Output of Execute pro开发者_StackOverflow中文版cessTask but not being able to access it further.
Please help.!
I think that you should echo the variable %Output% instead of using with Exit command.
Following example shows how to pass a string from batch file to SSIS:
- Screenshot #1 shows the contents of the batch file used in this example.
- Screenshot #2 shows the Execute Process Task configuration. The variable BatchOutput is of type string.
- Screenshot #3 shows that the Script Task
Success
is added after the batch Execute Process Task. - In the Script Task, I have the code shown under the Script Task code section to display the contents of the variable BatchOutput.
- Execution of the task should show the contents of the variable, which is actually the text echoed from the batch file. refer screenshot #4.
Script Task code: (Use the code given below to replace the Main() method in your Script task)
VB Main() method code that can be used in SSIS 2005 and above
Public Sub Main()
Dim varCollection As Variables = Nothing
Dts.VariableDispenser.LockForRead("User::BatchOutput")
Dts.VariableDispenser.GetVariables(varCollection)
MessageBox.Show(varCollection("User::BatchOutput").Value.ToString())
Dts.TaskResult = ScriptResults.Success
End Sub
C# Main() method code that can be used only in SSIS 2008 and above
.
public void Main()
{
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::BatchOutput");
Dts.VariableDispenser.GetVariables(ref varCollection);
MessageBox.Show(varCollection["User::BatchOutput"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
Hope that helps.
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
精彩评论