# 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?

-

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.

-
On UNIX, you can put a control sequence in your prompt to 1) go to the start of the current line (CR, "\015") , and 2) clear from cursor to end of line (ESC + [2K, "\033[2K"). –  Mike DeSimone Jan 18 '10 at 15:00
Did I miss something about Windows being UNIX now? –  Joey Jan 18 '10 at 21:04
Not pretty syntax but works - thanks. –  Umber Ferrule Feb 21 '10 at 21:54

This really depends on the commands you are running as they may be configured to do this after they are run - you would want to see if they have a non verbose option (However, I doubt this would help).

The other thing to try would be to put this at the beginning:

@Echo off

Unfortunately though, I don't think you are going to have a lot of luck as I think all commands put a line break after they have finished (It is what returns/brings up the command prompt when finished.

Your best bet would be to use a post processing tool and simply remove the line breaks, but I do not know a good one to recommend.

-