0

Under Windows 10 Enterprise LTSC, I have a simple CMD ff.bat which contains:

powershell -Command (Measure-Command {ffmpeg.exe -hide_banner -i %* E:\%~n1.mkv}).ToString

In CMD> ff test.mp4 and ff "test.mp4" works but NOT

ff "E:\Serie.(2009).8x04.episode.FR.LD.WEBRip.x264-LiBERTY.[server.org.ru].mkv"

Given PowerShell error is:

Au caractère Ligne:1 : 60 + (Measure-Command {ffmpeg.exe -hide_banner -i Serie.(2009).8x04.episode.FR.LD.WEBRip.x264-LiBERTY.[server.org.ru].mkv ... +
~ Nom de propriété manquant après l’opérateur de référence. (Missing property after reference operator) Au caractère Ligne:1 : 144 + ... .FR.LD.WEBRip.x264-LiBERTY.[server.org.ru].mp4 E:\Serie ... + ~ Nom de propriété manquant après l’opérateur de référence. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingPropertyName

I guess the problem comes from the .-[]():\ and brackets and parenthesis characters found in the file name. Could you give me the proper syntax for this to work in CMD, please. As a bonus, you can give me the syntax to make it work in PS if it can. Please note I'm a complete newbie in PowerShell and need examples more than suggestions. Thanks in advance, Marc.

  • try with `powershell -Command "(Measure-Command {ffmpeg.exe -hide_banner -i %* """E:\%~n1.mkv"""}).ToString"` – npocmaka Nov 22 '18 at 10:20
  • @npocmaka Probem with that approach is you never know what possibly double quoted arguments are contained in `%*` and break the outer double quotes. –  Nov 22 '18 at 10:31
  • Possible answer https://stackoverflow.com/questions/45760457/how-to-run-a-powershell-script-with-white-spaces-in-path-from-command-line/45762288#45762288 – vrdse Nov 22 '18 at 16:59

1 Answers1

0

Your assumption here...

I guess the problem comes from the .-:\ and brackets and parenthesis characters found in the file name

...is correct.

There are special characters in every language use case. They can only be used as defined in the language specification. If any string you are using has these types of characters, you either need to remove them or properly terminate them.

<#
LONG DESCRIPTION
    Windows PowerShell supports a set of special character sequences that 
    are used to represent characters that are not part of the standard 
    character set. 

    The special characters in Windows PowerShell begin with the backtick 
    character, also known as the grave accent (ASCII 96). 

    The following special characters are recognized by Windows PowerShell: 

        `0    Null 
        `a    Alert 
        `b    Backspace 
        `f    Form feed 
        `n    New line 
        `r    Carriage return 
        `t    Horizontal tab 
        `v    Vertical tab 
        --%   Stop parsing
#>
Get-help -Name about_Special_Characters 

Even parenthesis, braces, brackets, also have special meaning, and cannot be used in file names.

PowerShell - Special Characters And Tokens

So, by what you show in that failing file name, you need to rename those.

postanote
  • 15,138
  • 2
  • 14
  • 25