windows - CMD环境下PowerShell中的语法问题
问题描述
在 Windows 10 Enterprise LTSC 下,我有一个简单的 CMD ff.bat,其中包含:
powershell -Command (Measure-Command {ffmpeg.exe -hide_banner -i %* E:\%~n1.mkv}).ToString
在 CMD> 中ff test.mp4
有效ff "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 的新手,需要的示例多于建议。在此先感谢,马克。
解决方案
你的假设在这里...
我猜问题来自文件名中的 .-:\ 和括号和括号字符
...是正确的。
每个语言用例中都有特殊字符。它们只能按照语言规范中的定义使用。如果您使用的任何字符串具有这些类型的字符,您需要删除它们或正确终止它们。
<#
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
即使是圆括号、大括号、方括号,也有特殊含义,不能用在文件名中。
因此,根据您在该失败文件名中显示的内容,您需要重命名它们。
推荐阅读
- javascript - React Hooks 的嵌套数据结构问题
- jquery - .toggle() 不适用于附加元素
- python-3.x - 从列中提取数字并将它们作为数据框 pandas 中的 int 范围放在一个空列中
- eclipse - 在 Eclipse 中导入 LibGDX 项目:无法解析:项目:core
- python - 在 Python 中的时间范围之间从日志文件中导出数据
- apache-spark - 如何将火花镶木地板插入 HIVE 表?
- android - 根据实时保存在 Firebase 中的数据进行搜索
- go - 如何用 Go 语言解压缩字符串
- java - 为什么有很多以 0 结尾的非公共低级 Java 方法?
- android - 在 Android Studio 中重命名包名称后出错