Question Duplicate/clone/re-route A Stream

kolonuk

Member
Hi All,

Yet another teaser that's been bugging me lately.

We have several documents that we print in postscript directly to a cups printer using
Code:
OUTPUT STREAM prnt THRU  VALUE("lp -d" + v_printer)
and then
Code:
PUT STREAM prnt UNFORMATTED v_Postscript SKIP.
Those "put streams" are littered throughout the code, merrily dumping postscript out to the printer. What I now want to do is to record what goes out through those streams (so that I can re-create the print jobs), but only for a particular document.

I've trawled the OE language reference, and done some searches here, but either no one else is interested in redirecting or cloning stream data, or I'm not searching for the right thing!

I could change the stream location to a file and do with it what I will - this has it's own complexities I wont get into, but needless to say this will be my approach if nothing comes of this post.

So, my question is, how to I capture stream data to, say another stream or a variable? Is the stream in memory somewhere until it is closed?

Thanks in advance!
 
Last edited:

RealHeavyDude

Well-Known Member
I am afraid there is no solution within the ABL to what you want to achieve. Even though in more recent version of OpenEdge you can grab the handle of a stream that you defined, there is not much you can do with it as you may only access a handful of attributes but not one single method ...

Heavy Regards, RealHeavyDude.
 

kolonuk

Member
Thanks RHD.

I did experiment with stream handles last week, and while you can't change the location of the stream, you can switch the output of a stream-handle between two streams:
Code:
DEF VAR hprnt AS handle NO-UNDO.
DEF STREAM stream1.
DEF STREAM stream2.

OUTPUT STREAM stream1 THRU VALUE("lp -dkp1").
OUTPUT STREAM stream2 TO /tmp/testprint2.txt.

hprnt = STREAM stream1:HANDLE.
PUT STREAM-HANDLE hprnt "line1" SKIP.

hprnt = STREAM stream2:handle.
PUT STREAM-HANDLE hprnt "line2" SKIP.

hprnt = STREAM stream1:handle.
PUT STREAM-HANDLE hprnt "line3" SKIP.

OUTPUT STREAM stream1 CLOSE.
OUTPUT STREAM stream2 CLOSE.
With this, "line2" is the only line in the file, whereas lines 1 and 3 are sent to the printer.

While this is close to what I wanted, it's not really feasible as I'd have to change almost 200 programs and includes to use the stream-handle, which is more time in checking and testing than is allocated to this project.

Still, something to bare in mind for future projects.
 

kolonuk

Member
Me again.

There was no way round this, so I folded and opted to put the stream to a file initially, then I can copy it to an archive, and also send it to the printer. Seems a bit manual to me, but still, it works.

And it wasn't as complicated as I suspected, so all it good!
 

TheMadDBA

Active Member
On Unix systems you can use the tee command to send output to multiple locations at once...

OUTPUT STREAM stream1 THRU VALUE("tee myfile | lp -dkp1")
 

GregTomkins

Active Member
Create your own version of 'lp' that reads from stdin, writes to the real 'lp', and also writes to whatever other file you want, or otherwise mangles the input in some way to your liking. Put it in your $PATH ahead of the real 'lp'.

Kind of an 'lp proxy' or an 'lp wrapper'. If you're feeling lucky, you could do it in ABL, but I'd do it in Java or Python.
 
Top