Open Lotram opened 1 year ago
After some more investigation, I found out that fix works:
from invoke.runners import Local
class CustomRunner(Local):
def _write_proc_stdin(self, data):
if data == b"\n":
data = b"\r\n"
return super()._write_proc_stdin(data)
namespace = Collection()
namespace.configure({"runners": {"local": CustomRunner}})
# namespace.add_collection(...)
I now wonder this is a problem from redis-cli
because it should handle \n
differently, or invoke
, because it should not send \n
when pressing Enter.
@Lotram It's most definitely redis-cli as CRLF isn't really supported by any Linux system or Invoke (outside of Windows).
Ok but then why does the shell open through invoke behave differently from the regular one / the one opened through os.execve(shell, [shell, "-c", command], env)
?
I think my issue is linked to https://github.com/pyinvoke/invoke/issues/733
python: 3.10.5 invoke: 2.0.0 os: Ubuntu 20.04
I want to open a redis shell, using
redis-cli
.The problem is the "Enter" key prints a linebreak, instead of running the Redis command.
After some digging in the code, I found out the actual execution of the command in invoke is done by
os.execve(shell, [shell, "-c", command], env)
. If I run this line in a python shell, it works as expected, the issue only happens when running the code throughrunner._run_body
, probably because of a problem with the thread handling.I'd be happy to help debugging / fixing this issue, but I don't have a big understanding on how pseudo-terminals /
pty
/fcntl
work, so I'd need some help doing this.