www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/01/05:35:20

Date: Tue, 31 Mar 1998 21:54:32 -0800 (PST)
Message-Id: <199804010554.VAA22721@adit.ap.net>
Mime-Version: 1.0
To: viking AT flying-brick DOT caverock DOT net DOT nz,
djgpp Mailing list <djgpp AT delorie DOT com>
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Pipes and how to seek

At 09:59  3/30/1998 NZT-12DST, Eric Gillespie wrote:
>Stardate  8 Mar 98 14:22, Eli Zaretskii log entry:
>
>:: 
>:: On Sat, 7 Mar 1998, Nate Eldredge wrote:
>:: 
>:: IMHO, you should avoid setting the console to binary mode at all
>:: costs, since this have some nasty side-effects (e.g., you cannot
>:: interrupt a runaway program with Ctrl-C).  In my experience, it is
>:: never really needed anyway: if binary garbage is being sent to the
>:: screen, who cares if it gets truncated?
>First, thank you for replying to me...

I'm actually not sure that was me, but anyway...

>Yeah, I agree, but only in part - I do ACTUALLY want to print the garbage 
>heading through stdin, but it turns out the way I've been doing it, the 
>stdin can't be set to O_BINARY anyway 8-(, at least not in this situation:
>
>cat strayfile.binary | hexdump
>
>As you probably have figured out, I need the cat program to open stdin in 
>O_BINARY, not just hexdump.

As far as I can tell, it does. How do you tell that it doesn't?

Your program will have to put stdin in binary mode as well. The recommended
method is:

if (isatty(fileno(stdin))
   setmode(fileno(stdin), O_BINARY);

> I am also having problems when using stdin
>and then asking for a getch() directly after checking kbhit() - the 
>program locks up, though getch will work in other situations while using 
>stdin.  I sorted the problem out (temporarily by the following code):

This probably won't work in any case. `stdin' uses stdio functions and reads
through DOS, while `kbhit' and `getch' talk directly to the BIOS. If you mix
these, strange things will happen. Also see FAQ section 9.4.

>Another idea I intend to use this for is to take the output from dd or some 
>such utility - that way, I could examine the direct output from dd.
>
>I have also thought of something else - it seems what I want to do - using
>hexdump on its own without parameters brings up a list of files to choose 
>from, may get confused unless I explicitly provide a switch to tell 
>hexdump that stdin is connected to the input, i.e. hexdump -s
>Otherwise how is hexdump going to tell the difference between nothing (meaning
>read stdin) and nothing (display file list to browse)?

Sure, you could do that. The standard Unix behavior for such things is for
the program by itself (like `cat') to read from stdin, while special
behavior is activated by switches (like `-o file' or `--help').


Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019