Home > Archive > Cobol > August 2005 > Creating a tar file from COBOL
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Creating a tar file from COBOL
|
|
|
| Hi all.
COBOL: MF Server Express 4.0 SP2
OS: HP-UX 11i
Challenge: Create a tar package from within a cobol application.
Inside the COBOL application, I am cycling through a (sometimes rather
LARGE) random list of file names. Each file needs to be added to a tar
package that will be transmitted to a remote machine.
I've come up with two methods for this:
1) Build the names of the files into a single command line, then shell
out one time to the tar command so that it can create the archive (tar
cf mytar file1 fil2 ...).
2) Shell out for each individual file name using the tar command to add
it to the existing archive (tar [cr]f mytar file).
Option 1 is somewhat difficult because my command line could easily
grow to more than the command line limit set by HP-UX (currently 256
bytes I believe).
Option 2 is clumsy because I will use a lot of overhead with the
repeated system calls.
I'm looking for a better/cleaner/faster way to do this, if anyone knows
of one? >>fingers crossed<<
Perhaps there is a native compression utility within COBOL that I am
unaware of?
Any and all suggestions are welcome. Thanks in advance.
Chris
| |
|
| I've discovered a 3rd option (using pax).
I could build an output file containing the names of the files to be
archived, then 'cat' its outputs to the pax command at the end of the
routine (cat filelist | pax -c -f bundle.pax).
This would seem to solve my command line length problem, but still it
is rather clumsy.
Still looking for a better mousetrap.
Thanks.
| |
| Richard 2005-08-16, 5:00 pm |
| > Any and all suggestions are welcome.
>From man tar on Linux:
-T, -I, --files-from=F
get names to extract or create from file F
Write the list of files to file F and use this option, if available.
| |
| Richard 2005-08-16, 5:00 pm |
| > (tar cf mytar file1 fil2 ...).
> Perhaps there is a native compression utility
Note that tar is not a 'compression' utility unless you specify the Z
or z option or similar (if supprted).
| |
|
| Thanks Richard - Linux is a wonderful thing.
Unfortunately these optoins are not available on the version of tar
that ships with HP-UX 11i.
The use of pax gives me this same flexibility, but I am not sure if pax
is POSIX so that it will be supported across many different flavors of
UNIX.
| |
|
| Yes - I should have been more clear on that. The intention is not
really to compress the files (though that would also be nice), its more
to consolidate them into a single file for relay to multiple servers.
| |
| clvrmnky 2005-08-17, 4:59 pm |
| On 17/08/2005 9:02 AM, Chris wrote:
> Thanks Richard - Linux is a wonderful thing.
>
> Unfortunately these optoins are not available on the version of tar
> that ships with HP-UX 11i.
>
> The use of pax gives me this same flexibility, but I am not sure if pax
> is POSIX so that it will be supported across many different flavors of
> UNIX.
>
pax _is_ POSIX.2. See the x/OPEN Portability Guide 4.0.
tar is not strictly POSIX, but is often recommended on POSIX systems for
portability reasons and based on it's BSD Unix legacy. But it is not
part of any POSIX standard I know about.
| |
| Michael Wojcik 2005-08-17, 4:59 pm |
|
In article <1124283751.625007.132370@f14g2000cwb.googlegroups.com>, "Chris" <ctaliercio@yahoo.com> writes:
>
> The use of pax gives me this same flexibility, but I am not sure if pax
> is POSIX so that it will be supported across many different flavors of
> UNIX.
It is; more precisely, it's part of the Single UNIX Specification
version 3, which is simultaneously The Open Group Base Specifications
Issue 6, POSIX (IEEE 1003.1-2004 and 1003.2-2004), and ISO/IEC 9945-1
and 9945-2. (These are the so-called "Austin Group" participants.)
See:
http://www.opengroup.org/onlinepubs...lities/pax.html
http://www.opengroup.org/onlinepubs...9/idx/misc.html
SUSv3 is relatively recent (2004), but I believe pax has been in
POSIX since at least 2001.
Another alternative would be to generate the tar file within your
process. The tar file format is documented; there are probably open
source libraries to create tar files programmatically. By the same
token, if you did want compression you could use a library such as
Gailly and Adler's zlib to create an archive with compression.[1]
While these libraries are typically written in C, they generally
build on all modern Unix platforms without requiring any code changes
- just download and follow the instructions.
1. Actually, zlib (http://www.zlib.net) doesn't create zip archives
by itself, but it comes with a sample C program that does. There's
probably another open source library that will create zip archives
without doing any additional work.
--
Michael Wojcik michael.wojcik@microfocus.com
Please enjoy the stereo action fully that will surprise you. -- Pizzicato Five
|
|
|
|
|