在 VBS 中重定向到标准输出 [英] Redirection to standard output in VBS

查看:81
本文介绍了在 VBS 中重定向到标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

shcmd 中编写脚本时,您可以将 > 放在一行的末尾以获得该输出行重定向到一个文件.如果没有,则发送到标准输出.

When writing a script in sh or in cmd you can put a > at the end of a line to have the output of that line redirected to a file. If not, it is sent to the standard output.

此外,两者都有 echo 命令来将输出生成到标准输出(反过来,也可以重定向).

Also, both have the echo command to produce output to the standard output (which can, in turn, be redirected too).

如何在 VBS 脚本中执行这两件事?

How to perform those two things in a VBS script?

推荐答案

没什么不同.您只需要确保您的脚本与基于控制台的脚本主机 cscript 一起运行.

Nothing different. You only need to make sure your scripts are run with the console based script host cscript.

myscript.vbs:

myscript.vbs:

' WScript.Echo is a host-aware hybrid method. 
' in cscript, prints the message with final a new line feed, also accepts vary arguments (0 or more).
' in wscript, shows a message dialog window
WScript.Echo "test1", "arg2"

' WScript.Stdout.Write on the other hand is a more traditional way to write to standard output stream
' print the message as is with no new line feeds
WScript.Stdout.Write "test"
WScript.Stdout.Write "2"

命令:

cscript myscript.vbs

输出:

Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

test1 arg2
test2

还有一个选项可以防止在输出上显示横幅.

There's also an option to prevent to display banner on the output.

cscript //NoLogo myscript.vbs

输出:

test1 arg2
test2

重定向:

cscript //NoLogo myscript.vbs>output.txt

<小时>

PS:cscript 是仅在 Windows Server 操作系统上的默认脚本解释器.否则默认为 wscript.因此,最好使用特定的脚本宿主运行脚本.


PS: cscript is the default script interpreter only on Windows Server operating systems. Otherwise the default is wscript. Therefore it is a good practice to run the scripts with a specific script host.

要更改默认脚本主机,请查看 运行你的脚本

To change the default script host have a look at Running Your Scripts

有用的链接:

这篇关于在 VBS 中重定向到标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆