如何传递以"//"开头的参数到wsh脚本? [英] How to pass an argument that starts with "//" to a wsh script?
本文介绍了如何传递以"//"开头的参数到wsh脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我具有以下脚本(该脚本仅将第一个参数输出到控制台):
If I have the following script (that just prints the first argument to the console):
@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
WScript.Echo(WScript.Arguments.Item(0));
我尝试类似
C:\>test.bat "//test"
我收到以下错误
输入错误:指定了未知选项"//test".
Input Error: Unknown option "//test" specified.
尽管使用引号,但它是Windows脚本宿主的一个选项.
如何传递以//
开头的参数.命名参数?
Despite the quotes.It is taken as an option to the the windows script host.
How can pass an argument that starts with //
. Named arguments?
推荐答案
cscript //E:JScript //nologo "%~f0" // %*
传递双斜杠以结束cscript
自己的参数解析.
Pass a double slash to end the cscript
own argument parsing.
注释:我不知道它是否在任何地方都有记录,但已在Windows 7和10上进行了测试
note: I don't know if it is documented anywhere, but tested on windows 7 and 10
测试脚本:
Option Explicit
Dim argument
For Each argument In WScript.Arguments
WScript.Echo "argument: " & argument
Next
For Each argument In WScript.Arguments.Named
WScript.Echo "Named: " & argument
Next
For Each argument In WScript.Arguments.UnNamed
WScript.Echo "UnNamed: " & argument
Next
输出(抱歉,西班牙语语言环境):
Output (sorry, spanish locale):
W:\>cscript //nologo test.vbs //test
Error de entrada: Opción desconocida "//test" especificada.
W:\>cscript //nologo test.vbs // //test /one two
argument: //test
argument: /one
argument: two
Named: /test
Named: one
UnNamed: two
W:\>cscript test.vbs // //nologo //test /one two
Microsoft (R) Windows Script Host versión 5.812
Copyright (C) Microsoft Corporation. Reservados todos los derechos.
argument: //nologo
argument: //test
argument: /one
argument: two
Named: /nologo
Named: /test
Named: one
UnNamed: two
W:\>
这篇关于如何传递以"//"开头的参数到wsh脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文