1. It would read the files sent as a prompt via command task in Informatica.
2. It would exit with an errorlevel(returncode) 0 if either of the file/or both files is/are not empty.This essentially means our command task would succeed and the main session would start running.
3. However if both files are empty, script would return an errorlevel of 1. This would fail the command task as we had checked the properties tab of the command task to 'Fail task if any command fails'.
I would post the original script below and then would explain it:
@echo off
set file1="%1"
set file2="%2"
set minbytesize=20
FOR /F "usebackq" %%A IN ('%file1%') DO set size1=%%~zA
FOR /F "usebackq" %%A IN ('%file2%') DO set size2=%%~zA
if %size1% LSS %minbytesize% (
if %size2% LSS %minbytesize% (
echo.File size %size1% and ^< %minbytesize%
echo fail
exit 1
) ELSE (
echo.File size %size2% and ^>= %minbytesize%
echo pass
exit 0
)
)ELSE (
echo.File size %size1% and ^>= %minbytesize%
echo pass
exit 0
)
- The command @echo off turns off the prompt to display each command on screen. If its set to on we would see each command that gets executed, displayed on screen.
- Now to the script. We have defined two variables file1 and file2. These two variables would hold the prompts sent from command task i.e. it would have the file path. In this case lets say variable file 1 would have value C:\Informatica\PowerCenter8.6.0\server\infa_shared\Srcfiles\a.csv and variable file 2 would have value C:\Informatica\PowerCenter8.6.0\server\infa_shared\Srcfiles\b.csv (please see my previous post in case you are confused)
- One more variable with the name minbytesize is defined and its assigned a value of 20 bytes.
- In the next two lines of code which looks a bit weird, whta happens is a for loop to read the contents of the file, the size of the file is determined and assigned into two variables size 1 and size 2.
- Next lines of code are self-explanatory. It goes like this:
#check whether file2 is also less than 20 bytes
If size of file2 is less than 20 bytes(
echo the size of file1 (or file 2 or both as per your need) and exit with errorlevel 1(failure;command task fails)
)else
#this means file 2 is greater than 20 bytes
(
echo the size of file 2 and exit with errorlevel 0(success; command task succeeds)
)else
#this means file 1 itself is greater than 20 bytes
(
echo the size of file 1 and exit with errorlevel 0 (success; command task succeeds)
)
Kindly provide your valuable suggestions as comments. Some wise guy has rightly said 'To err is Human'. So please feel free to correct me wherever you feel I have made a mistake or if there would have been an easier solution.
No comments:
Post a Comment