How to pass a command with spaces and quotes as a single parameter to CScript?

前端 未结 2 420
自闭症患者
自闭症患者 2020-12-19 13:02

I\'m using CScript to run a VBScript file, and I need to pass a command line to the script where the parameter includes both spaces and quotes. The entire command needs to

相关标签:
2条回答
  • 2020-12-19 13:37

    You have two options.

    The first is easy enough--escape the quotes using the carat (^).

    C:\> CScript myscript.vbs //Nologo "cmd.exe /c ^"dir && del /q *.txt^""
    

    The second option is to use a different delimiter. In a command like this, the shell uses a space as a delimeter between parameters. But the shell allows others like semicolons, commas, equal signs, and tabs. By implementing one of these, you wouldn't need to surround parameters with quotes because spaces would no longer break your command line.

    0 讨论(0)
  • 2020-12-19 13:42

    It appears like you are trying to delineate values in your parameters. I suggest using something besides quotes and adding back the quotes. For example using tildes:

    Dim count
    For count = 0 To WScript.Arguments.Count-1
        WScript.Echo CStr(count) & " = " & replace(WScript.Arguments.Item(count),"~",chr(34))
    Next
    

    Passing:

    cscript myscript.vbs //Nologo "1 ~2 3~"
    0 = 1 "2 3"
    
    0 讨论(0)
提交回复
热议问题