0

Why does this .BAT line split with caret fail?

enter image description here

ChrisJJ
  • 1,904
  • 1
  • 24
  • 34

1 Answers1

2

Because not only does ^ continue the line by ignoring the linefeed, it also escapes the first character of the next line. So the > is treated as a literal instead of as redirection.

You can get the exact same error result using:

type C:\temp.txt ^> C:\temp2.txt

You can fix the multiline version by putting a space before the redirection

type C:\temp.txt ^
 > C:\temp2.txt

The rules are actually a bit more complex than what I have described. See jeb's explanation of how caret works at end of line

Community
  • 1
  • 1
dbenham
  • 119,153
  • 25
  • 226
  • 353
  • Thanks. "You can fix the multiline version by putting a space before the redirection" Since that space then appears, I'd remove the space before the ^. It there an escaped character that's safe to always use on the start of the next line as a sacrifice, consumed? – ChrisJJ Aug 10 '14 at 14:24
  • @ChrisJJ - I don't understand what you mean by "that space then appears". You can put as many spaces before the `>` as you want and it will not affect the output. If your were executing ECHO, then I could understand the concern, but this is a TYPE statement. – dbenham Aug 10 '14 at 19:02
  • I find spaces before the > do affect the output e.g. http://i.imgur.com/ETrF4Qy.png – ChrisJJ Aug 10 '14 at 21:50
  • @ChrisJJ - That affects the appearance of the parsed line when ECHO is ON. But it does not affect the output of TYPE that is redirected to your file. – dbenham Aug 10 '14 at 22:07
  • Agreed. (more characters) – ChrisJJ Aug 11 '14 at 21:40