Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16816

Re: How do we intercept file saving or output to stdout directly

From worley@alum.mit.edu (Dale R. Worley)
Newsgroups gnu.bash.bug
Subject Re: How do we intercept file saving or output to stdout directly
Date 2020-08-26 00:01 -0400
Message-ID <mailman.1278.1598414497.2469.bug-bash@gnu.org> (permalink)
References <1598249852364-0.post@n7.nabble.com> <87a6yinjhl.fsf@hobgoblin.ariadne.com>

Show all headers | View raw


almahdi <budikusasi@gmail.com> writes:
> How do we intercept and redirect file saving or output to stdout directly in
> bash, just like e.g
>
> xkbcomp $DISPLAY
>
> will output and generated a file, but what needed is to put it directly to
> stream of stdout which will be piped once.
...
> $ xkbcomp $DISPLAY /dev/stdout
> Error:            Cannot open "/dev/stdout" to write keyboard description
>                   Exiting

Normally, that should work.

But I get the same error message as you do.  I did a trace on xkbcom and
I see at the end:

open("/dev/stdout", O_WRONLY|O_CREAT|O_EXCL, 0666) = -1 EEXIST (File exists)
write(2, "Error:            ", 18Error:            )      = 18
write(2, "Cannot open \"/dev/stdout\" to wri"..., 56Cannot open "/dev/stdout" to write keyboard description
) = 56

The open() is done with the O_EXCL flag.  Reading the manual page
open(2), I see that O_EXCL requires that the open() call creates the
file.

It's not clear why xkbcomp has this behavior, but it seems likely that
this is done for a specific reason.  So you will have to ask whoever
maintains it.

I don't see any option that overrides this behavior.

However, as Robert said, many programs handle an argument "-" specially
as a reference to stdin or stdout.  And it turns out that (my version
of) xkbcomp does so:

$ xkbcomp $DISPLAY -
xkb_keymap {
xkb_keycodes "evdev+aliases(qwerty)" {
    minimum = 8;
    maximum = 255;
     <ESC> = 9;
    <AE01> = 10;
...

Dale

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: How do we intercept file saving or output to stdout directly worley@alum.mit.edu (Dale R. Worley) - 2020-08-26 00:01 -0400

csiph-web