Best way to capture print statements

217 views
Skip to first unread message

troyd1

unread,
May 2, 2013, 6:58:02 PM5/2/13
to jb...@googlegroups.com
I am working on a system that creates print jobs by turning the printer on and then using print statements.  I would like to be able to capture the output from the print statements into a variable in a program to do something with them (basically capturing the print job into a variable).

Here are my thoughts:

Isolate the code and execute it and use a capturing statement.

Do a como on statement and capture the output that way.  If I need to do this, is there a way to have the output only go to the como file?

I guess what I am looking for is a way to do this with minimal changes to the program.  Basically do a "printer on" and save all output to a variable or alternately a file.  I am on jbase 3.4 on an old version of linux.

Thanks in advance for any help.

uiterwyk

unread,
May 2, 2013, 10:54:12 PM5/2/13
to jb...@googlegroups.com
Troy,

Go look in $JBCRELEASEDIR/config/jspform_deflt

It is VERY well commented and you can throw commands in here to save the print job to a file before or after the print.

You will need to make a copy, calling it something like jspform_yourchiceofnames

You can then use SP-TYPE to assign this form to a form queue for your printer.

PLEASE NOTE:  You do not use the full name (jspform_yourchiceofnames) in the assignment, you ONLY use the second half, i.e.   yourchiceofnames

Alternatively, you can use SP-DEVICE PROG to send the output to a a program/script that saves stdin to a file and then pipes the file (as stdout) to lpr

HTH

Robert

Daniel Klein

unread,
May 3, 2013, 6:05:59 AM5/3/13
to jb...@googlegroups.com
You have lots of options here.

 If the report is a Hold Entry in the spooler, you can send this to a file using the (I) 'eye' option of the SP-EDIT command. For example, if you want to send Entry #42 to a file, enter

SP-EDIT 42 (I)

and you will be prompted for the destination "File name and record key".

A more direct way to accomplish this is with the 'jspcmds' command:

jspcmds COPY "filepath filename" job#

For example, the command...

jspcmds COPY "/tmp/printjobs myjob.txt" 42

will 'copy' hold entry #42 to the '/tmp/printjobs' directory with a filename of 'myjob.txt'.

Should you wish to also delete the spooler entry then use 'COPYDELETE' in place of 'COPY' in the above command.

***

A form queue can also be created like this:

        SP-CREATE FILE PROG cat > /tmp/file.txt

When a printjob is despooled, a file will be created in the specified directory and will be called 'MyPrintFile'. The caveat of this method is that each time a job is despooled to this queue, it OVERWRITES the previous file.

***

The most flexible approach is to redirect spooler output to a user-written Basic program. What this means is that spooler 'output' (stdout) becomes the 'input' (stdin) to your program. This gives you total control over the spooler output. A typical program will capture all of the data to a file and then do something with that 'file' (like email it, convert it to a PDF or some other format, ftp it to some other machine, etc, the possibilities are endless). Output can also be handled line-by-line as it is being despooled.

Here's some code you can start with:

0001     PROGRAM lptext
0002     INCLUDE JBC.h
0003     id = CHANGE(UNIQUEKEY(),'/',']2F') ;* create a unique item-id for the print job
0004     tempdirname = '/tmp'  ;* This directory must have 'rw' permissions
0005     OPENSEQ tempdirname:DIR_DELIM_CH:id TO outstream ELSE
0006         CREATE outstream ELSE NULL
0007     END
0008     LOOP
0009         numchars = SYSTEM(14)
0010     WHILE numchars DO
0011         INPUT line, numchars
0012         WRITESEQ line ON outstream ELSE NULL
0013     REPEAT
0014     WEOFSEQ outstream ELSE NULL
0015     CLOSESEQ outstream

The next step is to define the form queue. For example, if the program is cataloged in '/home/bin' then:

SP-CREATE FILE PROG /home/bin/lptext

All that's left to do is assign the queue and print something, e.g.

SP-ASSIGN =FILE
LIST MD SAMPLE 10 LPTR

Note that the above code assumes the system is running jBASE 4 or 5. To get it to run on jBASE 3 : 
 
1) Replace line 3 with:
 
    id = SYSTEM(21):'_':DATE():'_':TIME():'_':SYSTEM(9):'_':RND(32000)
 
2) Replace lines 5 through 7 with:
 
    OPENSEQ tempdirname:DIR_DELIM_CH:id TO outstream ELSE NULL
 
3) Add the line:
 
        openseq_creates = true
 
to the '$JBCRELEASEDIR/config/Config_EMULATE' file under the appropriate emulation section, if it does not already exist. This setting allows 'id' to be created if it does not previously exist.

Hope this helps,

Dan


--
--
IMPORTANT: T24/Globus posts are no longer accepted on this forum.
 
To post, send email to jB...@googlegroups.com
To unsubscribe, send email to jBASE-un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en
 
---
You received this message because you are subscribed to the Google Groups "jBASE" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbase+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

troyd1

unread,
Jan 28, 2014, 2:36:08 PM1/28/14
to jb...@googlegroups.com
Daniel, thanks for the reply.  I am finally back on this.  I did the option of redirecting the  output to a program.  I cannot get it to work.

I created a program as described.  I am on a 3.x version of jbase.

I created the formqueue by doing SP-CREATE PCAPT PROG /jbase/bin/lptext

I created a directory under /tmp called PRINTCAPTURE and gave it 777 permissions.  I am on an old version of linux.

I ran the program from the command prompt and it was giving me an error with the sequential file, so I tried saving the output and just opening and writing the output.

It does not seem to even be running the program.

Here is the code:
* PROGRAM lptext
 INCLUDE JBC.h
* id = CHANGE(UNIQUEKEY(),'/',']2F')
 id = SYSTEM(21):'_':DATE():'_':TIME():'_':SYSTEM(9):'_':RND(32000)
* tempdirname = '/tmp/PRINTCAPTURE'
* OPENSEQ tempdirname:DIR_DELIM_CH:id TO outstream ELSE
*   CREATE outstream ELSE NULL
* END
EXECUTE 'touch /tmp/PRINTCAPTURE/testtouch'
* OPENSEQ tempdirname:'/':id TO outstream ELSE NULL
OPEN 'PCAPTURE' TO PCAPTURE ELSE STOP
PREC = ''
 LOOP
   numchars = SYSTEM(14)
 WHILE numchars DO
   INPUT line, numchars
   PREC<-1> = line
*   WRITESEQ line ON outstream ELSE NULL
 REPEAT
* WEOFSEQ outstream ELSE NULL
* CLOSESEQ outstream
WRITE PREC ON PCAPTURE,id
CLOSE PCAPTURE
STOP

I added the execute touch to see if it was running.  If I run the from the command prompt by either doing lptext or /jbase/bin/lptext it creates the touch file.

If I do SP-ASSIGN = PCAPT
and then SP-ASSIGN ?, it is assigned correctly.  SP-STATUS shows the formqueue fine.

If I do LIST MD SAMPLE 10 LPTR, it does not create the touch file and if I go to SP-STATUS, there is no job there.  If I assign it to hold(HS) or another form queue, it prints fine.

What am I doing wrong.  I feel like I am 99% there, but missing something.

Any suggestions?

troyd1

unread,
Jan 28, 2014, 2:42:43 PM1/28/14
to jb...@googlegroups.com
Also, I tried SP-ASSIGN = PCAPT HS
 and when doing LIST MD SAMPLE 10 LPTR, it created a hold entry.
This is the 12th form queue, so there is a hold entry in /usr/jspooler/jobs/formqueue_12.

Not sure what this means or affects, just more info.

On Friday, May 3, 2013 5:05:59 AM UTC-5, Daniel Klein wrote:

troyd1

unread,
Jan 28, 2014, 2:57:14 PM1/28/14
to jb...@googlegroups.com
Following up on my last post, is there a way to find the hold number if I sent the job to hold.  I could then possibly pull the file from the formqueue.


On Friday, May 3, 2013 5:05:59 AM UTC-5, Daniel Klein wrote:

Daniel Klein

unread,
Jan 28, 2014, 5:33:55 PM1/28/14
to jb...@googlegroups.com
I think the piece that is missing is 'openseq_creates = true' in the '$JBCRELEASEDIR/config/Config_EMULATE' file, under the appropriate emulation section.

Dan

troyd1

unread,
Jan 30, 2014, 7:39:03 AM1/30/14
to jb...@googlegroups.com
I checked and it is there.  I think the biggest point is that it is not executing the program when printing. It should correct?

troyd1

unread,
Jan 30, 2014, 7:59:49 AM1/30/14
to jb...@googlegroups.com
I tried a different path.  I found that SYSTEM(20) is the last hold entry.  I did a test and was able to create the hold entry and now I know the hold number and can find the file.  My issue now is that the hold entry has rw permissions and is owned by root and I cannot do anything with it without using a jbase command.  I tried your suggestion of doing jspcmds COPY "/directory file" hold#, but it just creates a new file with the same permissions.  Is there a way I can set the permissions on the spooler directory so that I can read this file or else when I do the copy, read it?


On Tuesday, January 28, 2014 4:33:55 PM UTC-6, Daniel Klein wrote:

Daniel Klein

unread,
Jan 30, 2014, 10:35:41 AM1/30/14
to jb...@googlegroups.com
If it is not executing the program then the best way to start debugging this is to run this command from a Linux prompt:

jsp_scan > jsp.out

and attach the 'jsp.out' file to your reply.

Dan

troyd1

unread,
Jan 30, 2014, 4:12:31 PM1/30/14
to jb...@googlegroups.com
I just ran it with the -v option and only got the following:
jsp_scan - Version $Revision: 3.1 $
SpoolerDir=/usr/jspooler
 ** Error [ 201 ] **
Unable to open file /usr/jspooler/jspool_log

Daniel Klein

unread,
Jan 30, 2014, 5:00:26 PM1/30/14
to jb...@googlegroups.com
You have a real permissions issue, which is probably the reason your program does not run as it can't access the 'jspool_log' file.

I'd advise trashing this spooler and creating a new one, but make sure 'umask 0' is set before running 'SP-NEWTAB'.

Dan

troyd1

unread,
Jan 30, 2014, 5:06:48 PM1/30/14
to jb...@googlegroups.com
When I try to redirect it to an output file, it keeps giving me an error, but if I do it to the screen, I get the followiing:
jsh tmi /tmp -->jsp_scan -v
jsp_scan - Version $Revision: 3.1 $
SpoolerDir=/usr/jspooler
 ** Error [ 201 ] **
Unable to open file /usr/jspooler/jspool_log

All the spooler info is owned by root and only has rw for root.

is there a way to change the permissions on the print jobs other than change the root umask?  I don;t want to do that.  I tried the setfacl command, but can't get that to work either.

Is there a user manual on the jspcmds?  The COPY command showed promise, but it just created a new file with the same file permissions.  If the copy would send output the the terminal. I could probably capture it that way.  This seems like it should be such an easy thing to capture the print output, but I am about at witts end.

On Thursday, January 30, 2014 9:35:41 AM UTC-6, Daniel Klein wrote:

troyd1

unread,
Jan 30, 2014, 5:13:17 PM1/30/14
to jb...@googlegroups.com
I would rather not do that as they have 11 form queue's set up and I really don't want to mess it up.  Is there a way using the jspcmds or another command to basically do a cat hold #.  I am thinking I could execute that and capture the output.  I think that would work fine.  Does the jspcmds COPY have a screen option?

Daniel Klein

unread,
Jan 30, 2014, 6:49:00 PM1/30/14
to jb...@googlegroups.com
That's an 11-line script that should take about 2 minutes to create. Here's a program that will do it for you, but you need to get 'jsp_scan' working (maybe run it as 'root' so that permissions are not a problem):

0001     EXECUTE @IM:'kjsp_scan > jsp.out'
0002     OPEN '.' TO curdir ELSE STOP 201,'.'
0003     READ jspout FROM curdir, 'jsp.out' ELSE STOP 202,'jsp.out'
0004     script = ''     ;* First line could be something like this: '#!/bin/ksh'
0005     numlines = DCOUNT(jspout,@AM)
0006     FOR lineno = 1 TO numlines
0007         line = TRIM(jspout<lineno>)
0008         label = line[1,7]
0009         BEGIN CASE
0010         CASE label  = 'FormQue'
0011             fqname  = FIELD(line,' ',2)[2,-1]
0012             IF fqname = 'STANDARD' THEN command = 'SP-DEVICE ' ELSE command = 'SP-CREATE '
0013             scriptline  = command:fqname
0014         CASE label  = 'DevType'
0015             devtype = FIELD(line,' ',2)[2,-1]
0016             scriptline := ' ':devtype
0017         CASE label  = 'DevName'
0018             devname = FIELD(line,':',2,99)
0019             scriptline := ' ':devname
0020             script<-1> = scriptline
0021         END CASE
0022     NEXT lineno
0023     WRITE script ON curdir, 'createqueues'



You could also do:

SP-EDIT entry# (I

Daniel Klein

unread,
Jan 30, 2014, 6:50:57 PM1/30/14
to jb...@googlegroups.com
I meant to add...

All you would need to do to rebuild the spooler is run SP-NEWTAB, make the script executable and then run it. Of course I would review it first to make sure it is doing what you want it to.

This spooler really needs to be refreshed and then your original program should work.

Dan

Reply all
Reply to author
Forward
0 new messages