Escaping special characters in cmd

2019-01-15 07:51发布

I have a Windows .bat script in which I try to run a command with password in parameter. The password I want to be able to use is ~!@#$%^&*()_+|-=\][{}';:"/.>?,<.

From what I've read here, I should escape ^&|\<> with ^. From what I assume, I should escape " with \".

This gives me something like that:

runme.exe /password:"~!@#$%^^^&*()_+^|-=^\][{}';:\"/.^>?,^<"

But it doesn't work - my target app responds with logon failure.

How should I escape all these characters to be able to hardcode the password in my batch (ignoring the security issues by now)?

标签: escaping cmd
2条回答
【Aperson】
2楼-- · 2019-01-15 08:08

Double the quote in the password and make sure the complete password is enclosed in quotes as well:

runme.exe /password:"~!@#$%%^^^&*()_+^|-=\][{}';:""/.>?,<"
查看更多
看我几分像从前
3楼-- · 2019-01-15 08:31

Give this a try, but if runme.exe's argument parser requires quotes as string encapsulators for passwords, the it's not going to work. If you need to have a quote in your password, then runme.exe needs to provide a way to escape it!

runme.exe /password:~!@#$%%^^^&*()_+^|-=\][{}';:"/.>?,<
查看更多
登录 后发表回答