Özenç B.
Özenç B.

Reputation: 1038

Passing arguments with escape characters to a batch file from PowerShell prompt

I have a batch file which runs a Python package, and it takes a string argument to run. The string, usually a Youtube link, has assignment symbols (=) so the argument must be enclosed in quotation marks to work properly. And it does work fine when I call it from command prompt like so (the file's path is set in environment variables so it can be called directly with its name):

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

This command works fine on CMD prompt, as I said, but on PowerShell everything after = symbol is discarded. How can I get this batch file to work properly in PowerShell prompt, which is my go to terminal?

script-name.bat file itself looks like this:

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

Edit: The command and output clearly shows how the rest of the link is discarded:

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

Upvotes: 1

Views: 216

Answers (1)

JosefZ
JosefZ

Reputation: 30113

From PowerShell, escape double quotes as follows:

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

or

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

or

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

or even

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

Upvotes: 6

Related Questions