2

I'm using FFmpeg on Windows where I need to insert an \r\n in a parameter itself.

ffmpeg … -headers "X-Test: Test\r\nX-Test-2: Test 2\r\n" …

While this will work fine under Linux and such, it does not work from a normal Windows 10 command prompt. It also does not work under Bash under Windows. In both cases, a literal \r\n (backslash, r, backslash, n characters) are sent in.

I have tried using Alt+13 Alt+10, and while this appeared to insert characters, they were interpreted as 0xE299AA 0xE29799 by FFmpeg.

This question is similar to How can I insert a new line in a cmd.exe command?, except that I'm not tied to cmd.exe. I'm happy to use any shell as long as I can use it under Windows, if there are any suggestions. Is this possible via Powershell somehow? Or, maybe by putting my parameters in a text file and bringing it in as a parameter value?

phuclv
  • 26,555
  • 15
  • 113
  • 235
Brad
  • 5,686
  • 8
  • 52
  • 83

3 Answers3

2

In PowerShell, you can use backtick-r-backtick-n and use backticks in place of the backslashes before the r and the n for the CRLF portions of the command—backtick "r" backtick "n".

This only requires this change to the existing command

ffmpeg … -headers "X-Test: Test`r`nX-Test-2: Test 2`r`n"

Further Resources

Brad
  • 5,686
  • 8
  • 52
  • 83
Vomit IT - Chunky Mess Style
  • 40,038
  • 27
  • 84
  • 117
  • How do I parse the `stdout` for `wmic logicaldisk get size,name,caption`?? i know `\r\r` will chop up all of the lines, but im lost beyond that :( – oldboy Dec 31 '19 at 07:00
  • well, im doing everything from a nodejs script, so ideally i believe i need a command prompt command. exactly, ideally i would simply like all of the values comma separated with no column value for each disk in an array. [i posted a question about it here](https://superuser.com/q/1513664/650420), but it got closed due to lack of details lol – oldboy Dec 31 '19 at 18:56
  • [ive reposted the question here](https://superuser.com/q/1513761/650420) so that it can receive responses – oldboy Dec 31 '19 at 19:06
1

Bash has $'…' syntax for this. It should work regardless of the OS.

ffmpeg … -headers $'X-Test: Test\r\nX-Test-2: Test 2\r\n' …

From Bash Reference Manual:

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:

[…]

\n
newline

\r
carriage return

[…]

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
0

Pure batch solution. Much worse than powershell of course so it's for reference only

setlocal EnableExtensions EnableDelayedExpansion

rem Get CR and LF characters
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

(set LF=^
%=EMPTY=%
)

ffmpeg … -headers "X-Test: Test!CR!!LF!X-Test-2: Test 2!CR!!LF!" …

However it's unlikely that you really need the CR character because the C library will automatically convert between '\n' and the native new line character(s) on input/output so you just need to use LF

phuclv
  • 26,555
  • 15
  • 113
  • 235