I need to compress (zip) a flat file and mail the same as an attachment.
I had tried the following piece of code. But when i open the attachment in mail, the data is incorrect (displays all junk characters).
Please make sure that you have read our rules. And note:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.
Since you are using compress, what did you expect? It changes the file into a compressed data block file. Unless you are uncompressing it, the file probably looks the same as it does on the system you mailed it from. Compare the two files (the attachment and the compressed file on the original server).
Note, even tar may change the file where it will not be readable. Also, a tar file may not be viewable on some other servers.