在命令提示符中转义特殊字符

时间:2016-03-16 13:33:17

标签: cmd escaping

我试图在cmd中运行这行代码:

wscript.exe hidden.vbs "test.bat http://www.googlec.com/index.php?act=viewprofile&id=1"

但由于特殊字符"&""=",这才是真正发生的事情:

wscript.exe hidden.vbs "test.bat http://www.googlec.com/index.php?act"

我已经尝试用^逃脱它们,但它没有用。

如何正确逃避这些角色?

2 个答案:

答案 0 :(得分:0)

C:\Users\User>echo "test.bat http://www.googlec.com/index.php?act=viewprofile&id=1"
"test.bat http://www.googlec.com/index.php?act=viewprofile&id=1"

然后使用此代码

WScript.Echo WScript.Arguments(0)
WScript.Echo WScript.Arguments(1)

我们得到了

C:\Users\User>cscript //nologo "C:\Users\David Candy\Desktop\Bat and vbs\CMDLineArgs.vbs" "test.bat http://www.go
oglec.com/index.php?act=viewprofile&id=1"
test.bat http://www.googlec.com/index.php?act=viewprofile&id=1
C:\Users\User\Desktop\Bat and vbs\CMDLineArgs.vbs(2, 1) Microsoft VBScript runtime error: Subscript out of range

显示它已正确读取。

答案 1 :(得分:0)

首先尝试将args放在变量中

set vbarg = "test.bat http://www.googlec.com/index.php?act=viewprofile&id=1"
wscript.exe hidden.vbs %vbarg%