This is the mail archive of the
mailing list for the Cygwin project.
Re: Cat and Head Problems with Binary Files
- To: Jeffry T Ross <email@example.com>
- Subject: Re: Cat and Head Problems with Binary Files
- From: Fergus Henderson <firstname.lastname@example.org.OZ.AU>
- Date: Sun, 25 Jul 1999 15:13:51 +1000
- Cc: email@example.com
- References: <firstname.lastname@example.org> <000e01bed529$6000e780$0f8e5381@Toeplitz.mitre.org>
On 23-Jul-1999, Jeffry T Ross <email@example.com> wrote:
> I thought the suggestion to use dd was a good, although a bit excessive
> when one only wants to move bytes from a file to a pipe without any
> conversion. So I tried it:
> dd if=test1 > test2
> test1 was 1296 bytes and test2 became 1301 bytes.
> So then I tried dd directly to a file.
> dd if=test1 of=test2
> this worked fine.
> So now I don't suspect cat but the piping and redirection.
I think the symptom that you report above is a bug in `dd'
(i.e. `dd' has not been properly ported to Cygwin).
> The question is how does cygwin implement it's piping and redirection?
By default, stdin, stdout, and stderr are assumed to use text mode.
If a program such as `dd' wishes to use stdin/stdout/stderr in binary
mode, then it should be modified to do so.
The issue here is basically the same as passing extra flags to open()
and fopen() to say that files should be opened in binary mode.
It's a little bit more complicated, though, since stdin/stdout/stderr
are already open. However, there should be a way of changing the mode
of an already open file. I don't recall off-hand what it is, though.
(I vaguely recall some mention of a setmode() function, but I could be
way off base with that...)
> Is this problem imposed by the underlying WIN/DOS or is it a bug in BASH?
Bash doesn't know whether the underlying program (e.g. `dd') will use
the stream in text or binary mode, so there's nothing bash can do.
I suppose you could add special syntax for redirection in binary mode,
so that the user could type e.g. "dd if=test1 >@ test2", but
it makes much more sense for it to be the program's responsibility to
use its files in the right mode rather than for this to be the user's
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger email@example.com | -- the last words of T. S. Garp.
Want to unsubscribe from this list?
Send a message to firstname.lastname@example.org