【问题标题】:Syntax problem in PowerShell in CMD environmentCMD环境下PowerShell中的语法问题
【发布时间】:2018-11-22 08:12:06
【问题描述】:

在 Windows 10 Enterprise LTSC 下,我有一个简单的 CMD ff.bat,其中包含:

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

在 CMD 中> ff test.mp4ff "test.mp4" 有效,但无效

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

鉴于 PowerShell 错误是:

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。 (引用运算符后缺少属性) 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

我猜问题出在文件名中的.-[]():\ 以及括号和圆括号字符。 请给我正确的语法以使其在 CMD 中工作。 作为奖励,如果可以的话,你可以给我语法让它在 PS 中工作。 请注意,我是 PowerShell 的新手,需要的示例多于建议。 提前致谢,马克。

【问题讨论】:

  • 试试powershell -Command "(Measure-Command {ffmpeg.exe -hide_banner -i %* """E:\%~n1.mkv"""}).ToString"
  • @npocmaka 使用这种方法的问题是,您永远不知道%* 中可能包含哪些双引号参数并打破外部双引号。

标签: windows powershell batch-file cmd syntax


【解决方案1】:

你在这里的假设......

我猜问题出在 .-:\ 以及方括号和圆括号中 在文件名中找到的字符

...是正确的。

每种语言用例中都有特殊字符。它们只能按照语言规范中的定义使用。如果您使用的任何字符串具有这些类型的字符,您需要删除它们或正确终止它们。

<#
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 

即使是圆括号、大括号、方括号,也有特殊含义,不能用在文件名中。

PowerShell - Special Characters And Tokens

因此,根据您在失败的文件名中显示的内容,您需要重命名它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多