我想在cmd.exe的.bat脚本中指定一个多行PowerShell命令。 我显然还没有正确的换行符和/或引号。 我也尝试使用反引号作为换行符,但同样失败了。 请问如何正确输入这个命令?
PS C:\src\t> cat .\pd.bat
powershell -NoProfile -Command "Get-ChildItem -Path '../' -Filter '*.doc' | ^
Select-Object -First 1 | ^
ForEach-Object { notepad `"$_.FullName`" }"
PS C:\src\t> .\pd.bat
C:\src\t>powershell -NoProfile -Command "Get-ChildItem -Path '../' -Filter '*.doc' | ^
^ : The term '^' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:45
+ Get-ChildItem -Path '../' -Filter '*.doc' | ^
+ ~
+ CategoryInfo : ObjectNotFound: (^:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
cmd.exe
唯一的优势是内存占用更小(比 PowerShell 小几个数量级)时,如果你要启动 PowerShell,就直接使用 PowerShell。 - David C. Rankin