I'm searching for a method to check from a batchfile if a printer is
connected to LPT port. I want to print then the content of a directory with
a
dir anydirectory > lpt1
The command will be called during an application is running. If there is no
printer there is an error message printed to STDERR
"Write fault error on LPT1
Write, Retry, Ignore, Fail"
Can I check if a printer is present form a Batchfile?
Or is it possible to hide messages to stderr?
thanks in advance,
Klaus
The following sniffs the printer port addresses set for DOS printers,
including network connections between LPT1 and LPT4 ...
@%9 echo off
echo d0:408l8> ~tmp.scr
echo q>> ~tmp.scr
debug < ~tmp.scr | find "0000" > ~tmp.bat
echo %0 %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 goto:2nd> 0000.bat
~tmp.bat
:2nd
if %1%2==0000 echo There is no printer on LPT1
if not %1%2==0000 echo There is a printer on LPT1
if %3%4==0000 echo There is no printer on LPT2
if not %3%4==0000 echo There is a printer on LPT2
if %5%6==0000 echo There is no printer on LPT3
if not %5%6==0000 echo There is a printer on LPT2
if %7%8==0000 echo There is no printer on LPT4
if not %7%8==0000 echo There is a printer on LPT4
del ~tmp.???
del 0000.bat
Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/
Cool but most curious. I only have one printer connected (LTP1), and the
batch gave me this result,
There is a printer on LPT1
There is no printer on LPT2
There is no printer on LPT3
There is a printer on LPT4
Where is this ghost printer connected to LPT4? I don't even have connectors
for lpt 2-4. Somehow I feel cheated now. ;-)
This is the contents (dump) from the ~tmp.bat file.
0000:0400 78 03 00 00 00 00 80 9F x.......
Any idea why it reports a printer for a port that don't even exist? MODE
reports lpt 1-3 as existing but bios setup (Phoenix) only shows a
configuration for lpt1. What gives? (I know, off topic)
--
Todd Vargo (body of msg must contain my name to reply)
--
Eric P. van Westendorp Tel: +31(0252)210579
Reigerslaan 22 2215NN Voorhout Netherlands
Well that is definitely a matter of opinion.
Using third-party utilities makes "solutions" dependant on having additional
software.
I know that hard drives are cheap, but additional software takes up space.
Another thing, sometimes binary programs do bad, bad things... intentional,
and otherwise. By having a script create the program you can at least see
the source.
I'm sure your PRN program could be created with the Debug trick that Tom
used, if you wouldn't mind posting the source code?
Respectfully submitted,
TITLE PRNREADY.ASM
;Test LPT1 ready, exit with errorlevel
;Errorlevel 0 = LPT1 installed and ready
; 1 = I/O error, no paper or printer doesn't exist
CODE SEGMENT 'CODE'
ASSUME DS:CODE,SS:CODE
ORG 0100H
.RADIX 10H
MAIN PROC FAR
MOV AX,0201 ;Read printer status function
;in AH, errorlevel in AL
XOR DX,DX ;0 = LPT1
INT 17 ;Parallel printer BIOS
;Returns status in AH if
;printer is present
;AX register is not changed by INT 17H when printer doesn't exist
CMP AX,0201 ;Does printer exist?
JZ DOS_EXIT ;No exit errorlevel 1
;If bits 5 and/or 3 of AH register are set means error
TEST AH,28 ;Bits 5 and 3, no paper I/O err
JNZ DOS_EXIT ;Error, exit errorlevel 1
;If bit 4 of AH register is clear (not set) means printer not ready
TEST AH,10 ;Bit 4 set indicates selected
JZ DOS_EXIT ;Not selected,exit errorlevel 1
;Passed all tests so exit with errorlevel 0
DEC AL ;Ready, exit errorlevel 0
DOS_EXIT: MOV AH,4C ;Terminate program
INT 21 ;DOS
MAIN ENDP
CODE ENDS
END MAIN
;Debug script to create PRNREADY.COM
;Don't forget mt lines after INT 21 and at very end
NPRNREADY.COM
A
MOV AX,0201
XOR DX,DX
INT 17
CMP AX,0201
JZ 0118
TEST AH,28
JNZ 0118
TEST AH,10
JZ 0118
DEC AL
MOV AH,4C
INT 21
RCX
001C
W
Q
--
Eric P. van Westendorp Tel: +31(0252)210579
Reigerslaan 22 2215NN Voorhout Netherlands
E.P. van Westendorp <E.P.van.W...@inter.NL.net> wrote in message
news:3986D750...@inter.NL.net...
Well, LPT4 is not a 'documented' DOS port, so I guess almost anything
could happen. The DOS variable space I 'sniffed' in the batch is
supposed to be set aside for LPT port addresses (according the the PC
Mag ref I used), but it is clear that in your configuration some piece
of software has taken the liberty of using the two bytes associated with
the LPT4 (0000:040E and 0000:040F). I probably should have played it
safe and stuck with just the three 'documented' DOS ports.
--
Eric P. van Westendorp Tel: +31(0252)210579
Reigerslaan 22 2215NN Voorhout Netherlands
Thanks Tom. Oh I forgot to mention, my printer was turned off. I know Klaus
Mueller only asked about knowing if one is attached, but he should be
advised the routine does not tell if it's online (just trying to be
helpful).
>The source and a DEBUG script
>
> TITLE PRNREADY.ASM
>;Test LPT1 ready, exit with errorlevel
<snip>
(Posted only to alt.msdos.batch - the other one isn't accessible to
me.)
Nice piece of work, but the utility vs. batch question can be
addressed in such a way that the program logic remains in batch:
@echo off
echo a > }{.src
echo mov ax,201 >> }{.src
echo mov dx,%1 >> }{.src
echo int 17 >> }{.src
echo mov al,ah >> }{.src
echo mov ah,4c >> }{.src
echo int 21 >> }{.src
echo. >> }{.src
echo rcx >> }{.src
echo 10 >> }{.src
echo w >> }{.src
echo q >> }{.src
echo. > }{.com
debug }{.com < }{.src > nul
}{
followed by testing for the desired status numbers. I used your al
value of 01, but I'm not absolutely sure for the reason - my guess is
that it is to compensate for the presence of PRINTFIX (always returns
90 in ah), but it seems that if it *always* returns 90, then if it is
installed, the value is meaningless. Anyway, the point is to return
the raw data for processing in the batch program to satisfy those who
grudgingly allow use of scripts, but only to the minimum extent
absolutely necessary, that is, as replacements for low-level library
functions that aren't there.
(Aside: type nul > }{.com insead of echo. > }{.com as a way of
creating the file before DEBUG can complain that it doesn't exist
crashes the DOS window with (usually) a memory allocation error in NT
and Win95 on termination of DEBUG.)
T.E.D. (tda...@gearbox.maem.umr.edu - e-mail must contain "batch" in the subject or my .sig in the body)