0

I want to handle \x1b[6n terminal sequence in python (it returns cursor position). When I tried:

import subprocess as sp
proc = sp.Popen(["echo", "-e", "\\x1b[6n"], stdin=sp.PIPE)
print(proc.communicate()[0])

It gives me b'\x1b[6n'. But when I typed in bash:

echo -e "\x1b[6n"

It gives to me what I expected. How to handle it correctly in Python?

Vad Sim
  • 282
  • 5
  • 17
  • Using a subprocess for this is completely crazy. The immediate problem is that you are missing `text=True` or an explicit encoding; but this is obviously easier and better in every way with simply `print('\x1b6[2n', end='')` (omit the `end=''` if you really want the newline). – tripleee Mar 27 '22 at 15:45
  • ... Of course, much better still is to use a proper Curses library, which encapsulates all this nonsense. – tripleee Mar 27 '22 at 15:54

0 Answers0