作者:手机用户2602917665 | 来源:互联网 | 2023-02-12 17:25
如果我有以下脚本(只是将第一个参数打印到控制台):
@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".
尽管有引号.它被视为windows脚本主机的一个选项.如何传递以...开头的参数//
.命名参数?
1> MC ND..:
cscript //E:JScript //nologo "%~f0" // %*
传递一个双斜杠来结束cscript
自己的参数解析.
注意:我不知道它是否记录在任何地方,但在Windows 7和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
输出(抱歉,西班牙语语言环境):
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:\>