Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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

> echo foo

> _

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

> set /p x=foo<nul
> _

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:"^$"


share|improve this answer
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.