XCOM send file to Windows creates extra blank record/line in file
search cancel

XCOM send file to Windows creates extra blank record/line in file

book

Article ID: 225806

calendar_today

Updated On:

Products

XCOM Data Transport XCOM Data Transport - Windows

Issue/Introduction

Environment: 
XCOM for z/OS 12.0
XCOM for Windows Server 11.6 SP3.

Send file initiated from XCOM z/OS to XCOM for Windows.
There is an extra blank record created at the end of the file received on Windows and this extra record is unexpected by a Windows application that reads this file.
Need to know how to transfer the file without creating the extra record on windows?

Environment

Release : 11.6

Component : CA XCOM Data Transport for Windows

Resolution

XCOM traces for both z/OS and Windows show that XCOM is sending/receiving the same number of records and blocks on each side of the transfer i.e. no extra bank record is being written by XCOM to the Windows file.
When Windows writes the file it adds a CRLF (Carriage Return and Line Feed) to the end of each line in the file including the last one. 
If the transferred file is opened in a Windows editor like Notepad/Notepad++ the last CRLF appears to be an extra blank line e.g. file test1.txt contains 5 lines with "ABC" on each line but shows 6 lines with the last blank line:

If examine the file in hex e.g. PowerShell command "format-hex" it will show the hex characters 0D 0A (CRLF) at the end of the last line:
+++
PS C:\temp> format-hex test1.txt


           Path: C:\temp\test1.txt

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   41 42 43 0D 0A 41 42 43 0D 0A 41 42 43 0D 0A 41  ABC..ABC..ABC..A
00000010   42 43 0D 0A 41 42 43 0D 0A                       BC..ABC..
+++

Therefore the solution is that the Windows application that is processing the file needs to be able to handle the CRLF at the end of the last line.

One alternative option is to use an XCOM post-processing script to remove the final CRLF after the file has been transferred e.g. customise xcomend.bat to call a script to remove the final CRLF.
Support successfully did that using this PowerShell script xcomend.ps1 I created after finding references on the web on how to remove the CRLF from the last line of a file (including checking if the CRLF exists) e.g. https://stackoverflow.com/questions/11643043/remove-last-line-from-file-with-powershell :
+++
$file = $args.get(0).Substring(1)
write-host "-file: " $file
$stream = [System.IO.File]::Open($file,[System.IO.FileMode]::Open)
$stream.Position = $stream.Length - 2
$bytes = 0..1 | %{ $stream.ReadByte() }
$compareBytes = 13,10 # CR,LF
if ("$bytes" -eq "$compareBytes") {
    $stream.SetLength($stream.Length - 2)
}
$stream.Close()
$stream.Dispose()
+++
The new script xcomend.ps1 was placed into directory %XCOM_HOME% and this line was added to the end of the default xcomend.bat to process the transferred file with the script:
powershell.exe -command "& '%XCOM_HOME%\xcomend.ps1' \"-%file%\"" >> c:\temp\xcomend.out
(NOTE:  The final ">> c:\temp\xcomend.out" was only used to capture errors from debugging first attempts)

After running the script for the transferred file example test1.txt above. If open the file in Windows editor like Notepad/Notepad++ it now only shows 5 lines with no final blank line:


Using PowerShell command "format-hex" also shows the hex characters 0D 0A (CRLF) have gone from the end of the last line:
+++
PS C:\temp> format-hex test1.txt


           Path: C:\temp\test1.txt

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   41 42 43 0D 0A 41 42 43 0D 0A 41 42 43 0D 0A 41  ABC..ABC..ABC..A
00000010   42 43 0D 0A 41 42 43                             BC..ABC
+++

*** Please note this is an example and XCOM Support does not provide any support for custom post-processing scripts. ***