bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Regression -- can't read input w/stderr redirect


From: L A Walsh
Subject: Regression -- can't read input w/stderr redirect
Date: Sun, 18 Jun 2017 14:02:05 -0700
User-agent: Thunderbird

I think I've found why I keep getting random values for
my DPI on my X-server starting from **Cygwin**.

I read a binary value in the low byte in
the registry Dword (broken apart due to line length):

 my -r HKLM='HKEY_LOCAL_MACHINE'
 my -r MsWinNT='SOFTWARE/Microsoft/Windows NT'
 my -r DPI_Px='FontDPI/LogPixels'
 my -r proc_reg='/proc/registry'

 my -r pixels_key="$HKLM/$MsWinNT/CurrentVersion/$DPI_Px"
 my -r pixels_path="$proc_reg/$pixels_key"

 int dpi=$(ord $(<"$pixels_path" 2>/dev/null))


This used to work but now works _unreliably_.

(NOTE: I know that function won't work for values over 255,
but hasn't been a problem yet, so haven't needed to fix it).

Tried running it interactively, and got:

> int dpi=$(ord $(<"$pixels_path" )) -bash: warning: command substitution: ignored null byte in input

I've always expected the '0' bytes to terminate input so
my "ord" only picked up the 1st character, but I know
about the added message.

Side question: Why display that message if there are only
NUL's at the end?  I would think it normal for bash to
use and read NUL terminated strings.  So why the err message
in that case?  FWIW, if the null bytes are anywhere BUT
the end, then I'd see that as an error, but usually with
C and bash, a NUL-byte terminating a string seems a bit
"unremarkable". (no?)

Nevertheless, even with the warning, dpi returned with the
correct value:

 > echo $dpi
 120

But the warning looks sloppy, so tried:

 int dpi=$(ord $(<"$pixels_path" 2>/dev/null))
 # no error message, but also got (in my script):

 ./get_NT_DPI: line 13: $1: unbound variable

Line 13 is the 'ord' function which doesn't get a param:

 function ord() { printf "%d" "'$1" ; }


So why do I get no output when I redirect the error
message?

Easy to dup:

echo -n >/tmp/x x
#working:
a=$(ord $(</tmp/x))
echo $a
120
#not working
a=$(ord $(</tmp/x 2>/dev/null))
echo $a
0


p.s. - maybe ignoring NUL's at end of input would be a
good thing?











reply via email to

[Prev in Thread] Current Thread [Next in Thread]