【问题标题】:Passing arguments with escape characters to a batch file from PowerShell prompt从 PowerShell 提示符将带有转义字符的参数传递给批处理文件
【发布时间】:2020-01-25 20:01:12
【问题描述】:

我有一个运行 Python 包的批处理文件,它需要一个字符串参数来运行。该字符串(通常是 Youtube 链接)具有赋值符号 (=),因此必须将参数括在引号中才能正常工作。当我像这样从命令提示符调用它时它确实可以正常工作(文件的路径在环境变量中设置,因此可以直接使用其名称调用它):

script-name "https://www.youtube.com/playlist?list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f"

正如我所说,此命令在 CMD 提示符下运行良好,但在 PowerShell 上,= 符号之后的所有内容都将被丢弃。如何让这个批处理文件在 PowerShell 提示符下正常工作,这是我的终端?

script-name.bat 文件本身如下所示:

youtube-dl -r 1500K -o "D:\Downloads\Youtube Videos\%%(playlist)s\%%(autonumber)02d - %%(title)s.%%(ext)s" %1

编辑:命令和输出清楚地显示了链接的其余部分是如何被丢弃的:

PS C:\WINDOWS\system32> dl-playlist "https://www.youtube.com/playlist?list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f"

C:\WINDOWS\system32>youtube-dl -r 1500K -o "D:\Downloads\Youtube Videos\%(playlist)s\%(autonumber)02d - (ext)s" https://www.youtube.com/playlist?list

【问题讨论】:

  • 你试过用单引号代替双引号
  • @Jawad 是的,同样的结果,不幸的是
  • 您是否尝试将网址放入某个变量中?

标签: powershell batch-file


【解决方案1】:

来自 PowerShell,escape 双引号如下:

dl-playlist "`"https://www.youtube.com/playlist?list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f`""

dl-playlist '"https://www.youtube.com/playlist?list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f"'

dl-playlist `""https://www.youtube.com/playlist?list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f"`"

甚至

dl-playlist """https://www.youtube.com/playlist?list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f"""

【讨论】:

  • 呵呵,没想到这么简单。为什么两个外壳之间有区别?有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多