Skip to content Skip to sidebar Skip to footer

Why Is Data Missing When I Write To A Python Subprocess Stdin Pipe?

My python code looks like this: def test(): pipe = sp.Popen( ['test.sh'], stdin=sp.PIPE) data = ''.join([chr((s)%17) for s in range(0,33)]) os.write(pipe.stdin.fileno()

Solution 1:

range() is right side exclusive.

range(0, 33) is [0, ..., 32], probably because this way you can range(0, len(sequence)) without off-by-one errors.

Since 32 % 17 == 15 == 0x0f, the byte '\x10' you are expecting was never part of the list in the first place.

Edit 1: Also missing from the output are the zero characters '\x00'. If you use VALUE=$(cat) the output of cat is subject to processing by the shell.

SingleUnix/POSIX seems to be silent on the matter. It is however clear, that you cannot have '\0' as part of a shell variable's value (or name for that matter) since the Unix environment requires both to be C-style zero terminated strings. I actually would have expected the value of VALUE to be an empty string.

Edit 2 After some digging, I can say that at least the ash implementation ignores '\0' processing backtick-supplied input. Input is read until EOF and null characters are explicitly skipped.

bash does the same and even has an explicit (even if commented out) warning associated with the event.

Post a Comment for "Why Is Data Missing When I Write To A Python Subprocess Stdin Pipe?"