In addition to removing newlines from the regular output, also parse the output of the command executed to turn newlines into spaces, unless it's the last character of the line.