Re: Redirection of output
- Posted by Juergen Luethje <jluethje at gmx.de> Jul 06, 2002
- 422 views
Hi all, I wrote: > Hello Pete, > you wrote: >> On Mon, 1 Jul 2002 07:26:20 +0200, Juergen Luethje <jluethje at gmx.de> >> wrote: >>> how can a windows program detect, whether it's output has been >>> redirected to a file? >> I had a quick search for you and found this: [decisive reference to int #21, ax=#4400] > Thank you!! > That looks like the DOS-Version of the function I'm looking for, > but unfortunately I'm not able, to translate it to proper working > Eu code. <snip> After having one more look at Ralph Brown's interrupt list, now I managed to write an appropriate Eu function. (Maybe I could not imagine, that it is that simple. --------------------------------------------------------------->8--- redir.ex -------------------------------------------------------------------- include machine.e constant REG_LIST_SIZE = 10, CF = 1 global function output_redirected () -- returns TRUE or FALSE, or -1 on error -- (after Ralf Brown's Interrupt List, Release 61 (2000)) sequence reg_list reg_list = repeat(0, REG_LIST_SIZE) reg_list[REG_AX] = #4400 reg_list[REG_BX] = 1 -- handle (1 = StdOut) reg_list[REG_FLAGS] = or_bits(reg_list[REG_FLAGS], 1) reg_list = dos_interrupt(#21, reg_list) if and_bits(reg_list[REG_FLAGS], CF) = 1 then return -1 -- error else return (and_bits(reg_list[REG_DX], #8000) = 0) -- redirected to a file or (and_bits(reg_list[REG_DX], #0004) != 0) -- redirected to NUL end if end function -- Demo integer ofn puts(1, "Hello World!\n") ofn = open("redir.log", "w") printf(ofn, "redirected: %d", output_redirected()) close(ofn) --------------------------------------------------------------->8--- To see what the program does, call it the following ways: ex.exe redir.ex ex.exe redir.ex > re.txt ex.exe redir.ex > nul and after each call, read the text in redir.log. Thanks again Pete, and best regards, Juergen PS: Does anyone know how this could be done on Windows?