Subj : Re: redirection of stdout. To : Jasen.Betts@xspamp42.f531.n640.z3.f From : Charles Dye Date : Wed Mar 20 2002 08:48 pm From: raster@highfiber.com (Charles Dye) On Wed, 20 Mar 2002 08:00:29 GMT, Jasen.Betts@xspamp42.f531.n640.z3.fidonet.org wrote: >Hi All. > >(4dos/msdos:) > >is there a way (using 4dos) to detect from inside a batch file if stdout >has been redirected (to a file/pipe). I don't see any good way to do it using only internal 4DOS functions. But it's trivial for an external program to check the status of its stdout handle, which it inherits from 4DOS. This same general approach would also work under COMMAND.COM. @echo off rem REDIR.BTM rem Checks for redirection of the stdout handle if (%@search[chkredir.com]) ne () goto :already text | debug > nul a 100 mov bx,1 ; handle 1 = stdout mov ax,4400 ; ioctl Get Device Data function int 21 ; call DOS and al,82 ; does handle refer to the cmp al,82 ; standard output device? jne 113 ; if not, branch ahead mov ax,4c00 ; stdout not redirected, int 21 ; exit with errorlevel 0 mov ax,4c01 ; stdout was redirected, int 21 ; exit with errorlevel 1 r cx 18 n chkredir.com w q endtext :already chkredir.com echoerr The stdout stream was %@if[%?==0,not ,]redirected. -- Charles Dye raster@highfiber.com --- BBBS/NT v4.01 Flag-2 * Origin: Mach2 Systems (1:342/3) .