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?

6
  • Do you want a solution for Bash, Powershell, or cmd?
    – EBGreen
    May 24, 2018 at 18:16
  • @EBGreen Doesn't matter... any of these are fine as long as it's for Windows.
    – Brad
    May 24, 2018 at 18:21
  • @PimpJuiceIT That works in PowerShell's command line!!! Thanks! Do you want to post that as an answer?
    – Brad
    May 24, 2018 at 18:54
  • There you go just as you suggested with the example logic I've used in the past. May 25, 2018 at 0:03
  • @PimpJuiceIT Yes, that's what worked! Real simple, thanks.
    – Brad
    May 25, 2018 at 4:48

3 Answers 3

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

3
  • 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, 2019 at 7: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, but it got closed due to lack of details lol
    – oldboy
    Dec 31, 2019 at 18:56
  • ive reposted the question here so that it can receive responses
    – oldboy
    Dec 31, 2019 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

[…]

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .