Category : BASIC Source Code
Archive   : QBFAQR01.ZIP
Filename : QBREDIR.DOC

 
Output of file : QBREDIR.DOC contained in archive : QBFAQR01.ZIP
'Date: 02-06-92 (11:56)
'From: TONY ELLIOTT
'Subj: Pgm output redirection
'---------------------------------------------------------------------------
'Hello everyone,

'While writing a utility program for my company, there became a need to
'determine if the output of the program was being redirected to a file
'or another "non-visual" device. For example:

' Program > Output.Fil

'When typed at the DOS prompt, the above command will send all program
'output normally directed to the screen to the file "output.fil" instead
'(this applies only to BASIC PRINT statements .. third-party asm screen
'writing routines' output cannot be redirected). In any event, if output
'was being redirected, I didn't want the utility to prompt the user for
'any keyboard input because the prompt wouldn't be seen! The program
'would just seem to lock up.

'I wrote a little ASM routine that checks to see if output was being
'redirected, and if so, returns a value of -1 (TRUE) as a result of the
'function. For those interested, here it is. You'll need MASM 5.1 to
'assemble it ( masm redir; ). The resuting .OBJ can be used in QB4.x -
'PDS 7.1. Although it can be invoked harmlessly within the IDE, there's
'no way to redirect program output when it is running in the IDE.

'Example program for REDIR.ASM

DECLARE FUNCTION Redirected% ()

IF Redirected% THEN 'Since BEEP is redirected
FOR X% = 1 TO 3 ' let's make some noise
FOR I = 400 TO 1000 STEP 40 ' using SOUND so we know
SOUND I, I/1000 ' this routine works.
NEXT
NEXT
PRINT "This message will be sent to file or device targeted"
PRINT "by the > symbol."
ELSE
PRINT "Not redirected."
END IF

;Different file here

;The following is the assembly langauge source code for the Redirected%
;function. It's not compilcated, but it serves a useful purpose.

; REDIR.ASM
; Redirected% - Returns -1 (TRUE) if the current program's output is
; being redirected. That is, the ">" was used on the DOS command line when
; the program was invoked:
;
; Program > Output.TXT
;

.model medium, basic
.code

Redirected proc

mov ax,4400h ;IOCTL - Get device info
mov bx,1 ;For the "standard output device"
int 21h ;Call DOS
xor ax,ax ;Assume NOT redirected
test dl,16 ;Is redirection active?
jnz @f ;If not, return 0 (false)
mov ax,-1 ;If so, return (-1) true
@@: ret ;[shouldn't the label be @F?]

Redirected endp
end

;--------End of assembly listing---------------------

;For those of you without MASM 5.1, you can call my BBS (404-928-7111)
;and download this routine (source and .OBJ) and example program. It's
;in QBREDIR.ZIP.


  3 Responses to “Category : BASIC Source Code
Archive   : QBFAQR01.ZIP
Filename : QBREDIR.DOC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/