【问题标题】:Using command line arguments in VBscript在 VBscript 中使用命令行参数
【发布时间】:2011-01-29 00:15:53
【问题描述】:

如何在 VBscript 中传递和访问命令行参数?

【问题讨论】:

    标签: command-line vbscript command-line-arguments


    【解决方案1】:
    Set args = Wscript.Arguments
    
    For Each arg In args
      Wscript.Echo arg
    Next
    

    在命令提示符下,像这样运行脚本:

    CSCRIPT MyScript.vbs 1 2 A B "Arg with spaces"
    

    会给出这样的结果:

    1
    2
    A
    B
    Arg with spaces
    

    【讨论】:

    • 您可以直接使用WScript.Arguments.Item(0) 访问它。第 0 项不是命令的名称(与其他语言一样);在上面的 Aphoria 示例中,它将是字符串“1”。
    【解决方案2】:

    如果您需要直接访问:

    WScript.Arguments.Item(0)
    WScript.Arguments.Item(1)
    ...
    

    【讨论】:

    • 您还可以将文件拖放到资源管理器中的脚本上,这将运行脚本并将第一个参数设置为文件路径和名称。
    • 你可能想用WScript.Arguments.Count这个。
    • 我将如何传递一个数组对象,例如像使用相同方法的 json 对象,即使用 WScript.Arguments?
    猜你喜欢
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2014-08-03
    • 2013-04-01
    • 1970-01-01
    • 2018-01-10
    • 1970-01-01
    相关资源
    最近更新 更多