Symbols that do not make it from the master to the slave pseudo-terminal

I'm currently trying to send binary data via pexpect. For some reason, the data goes through only a search, with the exception of 0x04, which is simply skipped. I traced the pexpect call to determine that everything that happens is the os.write () call on the file descriptor opened from the pty.fork () command.

Any ideas?

(sample code that illustrates the problem)

import os, pty, sys pid, child_fd = pty.fork() if pid: # Parent os.write(child_fd, b"'\x04hmm\x04'\n") buf = os.read(child_fd, 100) print buf else: # Child text = sys.stdin.readline() print ''.join(["%02X " % ord(x) for x in text]) 

Result:

 $ python test.py 'hmm' 27 68 6D 6D 27 0A 
+4
source share
1 answer

0x04 is ^ D, which is the end-of-file keystroke. Is pty installed in raw mode? Maybe the driver ate it.

If you do this:

 os.write(child_fd, b"'\x04hmm\x16\x04'\n") 

you can see that the driver is actually translating. \x16 is the same as ^ V, this is how you quote things. Of course, the transfer will occur only from the master (pretending to be a physical terminal) and subordinate. A pretended physical terminal is where (on a regular terminal device) a person types

I'm not sure how to make the driver stop doing this. If a child sets its terminal to raw mode, then this is likely to do so.

+2
source

All Articles