Re: Screen printing with control and p
Posted in 1995
paul sellars (paul@boothbc.demon.co.uk) wrote: : In 4GL control and p will output the screen contents to the file : named in the environment variable DBSCREENOUT. : Does anyone know of a way to pipe the output to a script file : or call the control and p function from 4GL ? : Our users want to be able to use a single key stroke to print a screen : immediately. Thanks in advance for any help. : -------------------------------------------------------------------------- : paul sellars,humberside,u.k. : ========================================================================== This seems to be a common question and since I haven't seem any answers to it yet I thought I'd give it some thought. The following shell script and C program seem to run fine on my SCO UNIX box with 4GL 4.11 & SE 5.01. Basically, all this stuff does is to capture data from the file specified in DBSCREENOUT and send it to the printer whenever there is some reasonable delay. Whilst my example shell script invokes a 4GL program, obviously ISQL/DBACCESS etc could be used instead. Please note that this code was written very quickly and could no doubt be improved... if someone has the time... please do. ### The Shell Script: : # runfgl - Run a 4GL program with screen print setup # PRINT_COMMAND="lp -s" DBSCREENOUT=/tmp/$$.sout export PRINT_COMMAND DBSCREENOUT cat /dev/null > $DBSCREENOUT # Create the empty output file tail -f $DBSCREENOUT | inf_print & P_PROC=$! # Note the process id fglgo $1 $2 $3 $4 # Run the 4GL program passing any arguments alone. kill -9 $P_PROC # Kill the print program now that we are finished ### The C Program: /* ** inf_print.c ** ** A little program to send its standard input to a pipe after ** a short delay ** ** Author: Scott McClintock ** MU Systems Pty Ltd ** Brisbane, Australia. */ #include <stdio.h> #include <signal.h> #include <setjmp.h> #define DELAY 5 /* Number of seconds to wait before printing */ #define DEFAULT_PIPE "lp -s" /* Default print command - Suits SCO UNIX */ FILE *Printer; /* Stream to send printed data out */ jmp_buf env; /* Environment saving structure */ extern char *getenv(); ClosePipe() { alarm(0); fclose(Printer); longjmp(env, 0); /* NOT REACHED */ } main() { int (ClosePipe)(); /* Function to close the pipe */ char PipeCommand[256]; /* This will contain the Print Command */ char Line[256]; /* A line of input data */ short FirstRead; /* First read for this loop flag */ /* Dig out the pipe command from the environment */ if(getenv("PRINT_COMMAND") == NULL) strcpy(PipeCommand, DEFAULT_PIPE); else strcpy(PipeCommand, getenv("PRINT_COMMAND")); /* Setup a loop using jumps */ setjmp(env); signal(SIGALRM, ClosePipe); /* Now Loop Getting the Data */ FirstRead = 1; while(1) { gets(Line); /* If this is the first line we've got, open the pipe */ if(FirstRead) { if((Printer = popen(PipeCommand, "w")) == NULL) { fprintf(stderr, "Cannot open Pipe: %s\\n", PipeCommand); exit(1); } FirstRead = 0; } fprintf(Printer, "%s\\n", Line); alarm(DELAY); } /* NOT REACHED */ } ##### END of CODE ###### I hope this helps with this problem... I'm happy to receive some feedback. cheers, Scott. =========================================================================== Scott McClintock Email: scott@musys.mpx.com.au MU Systems Pty Ltd Brisbane Australia ===========================================================================