Dev Hack: Printing from a Map - Using Shell Commands Inside a Map Design
Contributed by Jake Hughes, Support Engineer at Pervasive Software, Inc.
A less well-known feature of the Pervasive Map Designer is its
ability to embed shell commands within a map. This gives the Map
Designer yet another edge of versatility and power while keeping the
interface as simple as possible. As an example of it's usefulness, here
are the steps for printing the output files of a transformation.
Printing from a transformation is a capability that can come in
handy in certain situations. For instance, if some records are
rejected, it could be good to immediately see a printout of the problem
records to spot the errors. A printout of the output file could also be
useful for a quick eyeball proofing check, or to show executives or
managers an example of the output.
If someone needed printed output from a transformation, they might
not be aware that such a thing is possible using Pervasive® Data
Integrator™. However, since there is a fairly simple shell command to
print a file, and the Map Designer can make shell commands, printing an
output file from a map design is quite simple.
The variations in printers make it very difficult to directly embed
the functionality, but that variability can be accounted for in the map
design. The PCL section of the printer manual will have specifications
on the correct options needed by the printer driver being used. Setting
these options correctly in the map is essential. Because of that,
higher-end printing hardware with good documentation is a requirement.
Three steps to print from a map:
-
Create, test, and save a map design that would create an output file
compatible with your printer, generally with .prn as the file
extension. Refer to the PCL section of the printer manual for
specifications.
If you would like a quick look at how this works, create a simple
one-to-one map of the Tutor1.asc file provided with Pervasive Data
Integrator. Most printers will print a simple delimited ASCII file
although the formatting may be odd or parts of it may run off the page.
Those PCL specs are the key to better formatted output.
-
Add a command line to one of the events in the map design. The
AfterTransformation event in the Transformation and Map Properties
makes the most sense since the output file will be fully created or
updated at that point.
Example 1: Shell("cmd /c copy " & Chr(34) & Targets(0).Filename & Chr(34) & " \\printserver\Example_Printer")
This command line will print the target file, regardless of its name
or location by using the metadata expression Targets(0).Filename. The
filename parameter does not need to be changed to the exact name of the
file. This parameter stays the same unless you would like to print the
reject file, in which case you would change the metadata expression to
Targets(2).Filename. Of course, a reject subsystem already has to be
set up in the map design and a reject file created as part of the map
before it will be possible to print the reject file. If you need to
print the source file, Sources(0).Filename is the correct expression.
-
Adjust the server name, printer name, and path to the printer in the
command line, and change the file parameter if a file other than the
target file is to be printed.
Example 2: Shell("cmd /c copy " & Chr(34) & Targets(0).Filename & Chr(34) & " \\texprint\Integration_Printer")
This would print the target file called mytargetfile.prn to the Integration_Printer on the texprint server.

That's all there is to it. Execute the map and it will create the
output *.prn file and the AfterTransformation event will trigger
sending that file to the printer.
This is just an example of what you can do with this little-known
feature of Pervasive Map Designer. Any similar task that can be
performed with a shell command can be executed in the same way. Simply
add the shell command line arguments to one of the triggering events
using the sample syntax above as a guide.
One caution should be noted. Shell commands vary between platforms.
This example syntax will work fine whether the transformation is run
from the Map Designer design environment, called from a process step,
or executed by the Pervasive Integration Engine as long as it is run on
a Windows platform. The shell commands for executing via the
Integration Engine on a Linux box or other supported platform might be
a bit different. As long as you know your shell commands and adjust
according to runtime environment, you should still be able to take
advantage of this functionality.