First, I create a session by typing screen -S test1
, then I detach and type screen -S test1 -p 0 -X stuff "ls^M"
. This doesn't work, it just prints the characters "ls^M" in my session.
Without more details I don't know why it does not work for you but you can try other ways:
screen -S session -X -p 0 stuff "echo hello\r"
# OR
screen -S session -X -p 0 stuff $'echo world\r'