Home » Questions » Computers [ Ask a new question ]

How to stop the Windows command line from outputting an empty line after each command?

How to stop the Windows command line from outputting an empty line after each command?

I'm redirecting a batch file's output into a text file and don't want blank lines between each command. I realise I could post-process with a perl one-liner, but would rather not. Is there an option somewhere to suppress these unnecessary blank lines?

Asked by: Guest | Views: 337
Total answers/comments: 1
Guest [Entry]

"cmd always outputs a new line before it prints its prompt. This means that something like

> echo foo
foo

> _

will always have that blank line since echo prints a line break automatically. However, something like

> set /p x=foo<nul
foo
> _

will not have the empty line in between since above is the the trick that allows printing stuff without a trailing line break. Still, the prompt appears at the beginning of the next line.

This is presumably done to have the prompt always at the start of the line, regardless how messed-up the last command's output was. On UNIX-likes it's common to find your prompt in the middle of the line since the last command didn't print a newline.

But there doesn't seem to be a way to prevent his behavior.

You can easily pipe whatever you're doing there through

findstr /r /v /c:""^$""

though."