When obtaining the channel, set a separate pty so that EOF can be immediately obtained when the command ends. Otherwise, it is uncertain whether other processes in the system might affect stdout.
client.connect(hostname='127.0.0.1', port=2222, username='root', password='xxx',
timeout=10, banner_timeout=300)
cmd = "echo $PATH\n"
stdin, stdout, stderr = client.exec_command(cmd, get_pty=True)
stdout.readlines()
or
client.connect(hostname='127.0.0.1', port=2222, username='root', password='xxx',
timeout=10, banner_timeout=300)
channel = client.get_transport().open_session(timeout=10)
channel.get_pty()
channel.settimeout(10)
cmd = f'echo $PATH\n '
channel.exec_command(cmd)
stdin = channel.makefile('wb')
stdout = channel.makefile('r')
stdout.readlines()