How to get exit code in CDM

Categories: Scripts; Tagged with: ; @ January 14th, 2013 15:18

Requirement:

Need to catch the exit code, handle the Error based on the exit code.

Solution:

Use %ErrorLevel% – Almost all applications will set an exit code when complete (by conversion, 0 means successful).

 

Example 1:
copy file1.txt file3.txt
ECHO ...%ErrorLevel%

copy fileNotExisting.txt f.txt
ECHO %ErrorLevel%

Output:

“1 file(s) copied”
0

“The system cannot find the file specified.”
1

 

Example 2:

SET SSIS_EXIT_CODE=%ErrorLevel%
copy "%PKG_PATH%\Logs\….dtsx.log" ..
IF %SSIS_EXIT_CODE% NEQ 0 (
    EXIT /B %SSIS_EXIT_CODE%
)

 

Links:

http://ss64.com/nt/errorlevel.html
http://ss64.com/nt/exit.html

How to check the exit code of the last command in batch file?

SSIS: Append Header/Footer to flat file

Categories: Database; Tagged with: ; @ November 25th, 2012 17:52

Requirement:

Append additional header/footer to the destination flat file:

image

Solution:

Header/Footer can be added by several ways in SSIS, here is 3 ways I’m using:

Usinig Union in SQL :

-- Header

Select 'START' + convert(varchar(8),GETDATE(), 112)

-- Body

Union All

Select FULLNAME

from OVERSEA_ADDRESS

WHERE POSTAL_CODE = ''

-- Footer

Union All

Select 'END'+ Convert(varchar(8), Count(*))

from TWO_FA_OVERSEA_ADDRESS

WHERE POSTAL_CODE = ''

But sometimes the requirement is more complex, then we need to use Script task.

Script task using VB/C#

We can read/write file using VB or C#, and we can get the variables/paremeters, so basically, we can handle most of the requirement by Script task.

Reading file using VB:

Dim objReader As New System.IO.StreamReader(FILE_NAME)

' Read each line, and append the text into textLines
Dim currentLine As String
Do While objReader.Peek() <> –1
   currentLine = objReader.ReadLine()
   textLines.Add(currentLine)
Loop

Writing to file

' For loop the textLines
Dim index As Integer
For index = 0 To textLines.Count – 1
   Dim text As String = textLines.Item(index).ToString
   outStreamWriter.Write(text & vbNewLine)
Next
outStreamWriter.Close()

Using copy CMD

Generate the header, body, foot file and use CMD to combine the files:

copy header.txt+body.txt+footer.txt output.txt /y

Windows下列出所有文件清单的Dos命令

Categories: 分享; Tagged with: ; @ November 14th, 2011 22:40

Command: dir/s/b > list.txt
Output:

D:\PatchScriptsForAppTest\35315_deltas.xnr
D:\PatchScriptsForAppTest\35338_Part1_Translations.xnr
D:\PatchScriptsForAppTest\35338_part2_XeAppMenus.xnr
D:\PatchScriptsForAppTest\35345_Translations_IN_OUT.xnr

More info: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx?

MySql: backup and restore database using mysql/mysqldump

Categories: Database; Tagged with: ; @ July 31st, 2010 16:21

Backup database:

> (sudo) mysqldump db-name > db-backup.sql

Restore database:

> (sudo) mysql db-name (--no-date)(no-create-info) < db-backup.sql

CMD/DOS 变量 – CMD/DOS Variable Reference

Categories: Development Notes; Tagged with: ; @ March 5th, 2009 0:36
Variable

Sample Typical Value

%SystemDrive%

C:

%SystemRoot%

C:\WINNT
C:\WINDOWS

%WinDir%

C:\WINNT
C:\WINDOWS

%SystemDirectory%

C:\WINNT\System32
C:\WINDOWS\System32

%ComSpec%

C:\WINNT\system32\cmd.exe

%programfiles%

C:\WINNT\Program Files

%Temp%

C:\DOCUME~1\Usr\LOCALS~1\Temp from
C:\Documents and Settings\Usr\Local Settings\Temp

%Tmp%

%HOMEDRIVE%

C: The drive letter associated with the user’s home directory

%HOMEPATH%

The path to the user’s home directory (excluding drive):
\Documents and Settings\Guest

%OS%

Windows_NT (even on Windows XP machines
The operating system the user is running

%USERDOMAIN%

The name of the domain that contains the user’s account

%USERNAME%

The user’s name

%USERPROFILE%
%USERPROFILE%\Desktop

The user’s desktop folder

%CD%

The current directory.

%DATE%

Current date in the format set by the Date command

%TIME%

Current time in the format set by the Time command

%ERRORLEVEL%

A number defining exit status of a previous command or called executable

%RANDOM%

A random number between 0 and 32767.



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.