"\r"
in your first example (which doesn't work) isn't a new line character, it's a return character. You correctly use a new line character ("\n"
) in the second example, which does work."\n"
is a new line character, and will work whether it has characters after it or not