gpt4 book ai didi

vbscript - 如何输出传递给 VBScript 脚本的参数列表?

转载 作者:行者123 更新时间:2023-12-02 22:04:33 25 4
gpt4 key购买 nike

我有以下 VBScript 代码:

Dim returnVal
returnVal = "You did not pass me 4 arguments"

args = WScript.Arguments.Count

If args = 4 Then
returnVal = "The arguements you passed me are " & WScript.Arguments.Item(0) & " " & WScript.Arguments.Item(1) & " " & WScript.Arguments.Item(2) & " " & WScript.Arguments.Item(3)
end if

我想要的只是能够打印“returnVal”,这样如果我输入:

test.vbs 1 2 3 4

它将返回:

The arguments you passed me are 1 2 3 4

我该怎么做?

最佳答案

要输出到命令控制台窗口,您可以使用:

WScript.Echo returnVal 

WScript.StdOut.WriteLine returnVal 

但是您必须使用CScript主机才能使其工作,例如:

cscript.exe myscript.vbs

WScript 是 GUI 主机,因此不了解标准输入/输出/错误/辅助流。尝试执行 WScript.StdOut.WriteLine 将导致以下错误对话框:

---------------------------Windows Script Host---------------------------Script: d:\myscript.vbsLine:   12Char:   1Error:  The handle is invalid. Code:   80070006Source:     (null)---------------------------OK   ---------------------------

In a CScript.exe script you can still pop up GUI message dialogues using:

Msgbox "Hello World!" 

在 WScript 主机中使用 WScript.Echo 将在弹出对话框中显示消息,而不是打印到命令行窗口。

更多信息请参见:

Write Method (Windows Script Host)

有关 WScript 和 CScript 之间的差异以及如何在它们之间切换的更多信息:

Sesame Script Stop and Go (MS TechNet)

The difference between Cscript and Wscript is that Cscript is the command-line version of the script host and Wscript is the graphical version. This difference isn’t really noticeable unless your script uses the Wscript.Echo command.

关于vbscript - 如何输出传递给 VBScript 脚本的参数列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6860193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com