在sh或cmd 中编写脚本时,您可以在行尾放置>以将该行的输出重定向到文件。如果没有,则将其发送到标准输出。
此外,两者都有echo命令将输出生成到标准输出(反过来,也可以重定向)。
如何在 VBS 脚本中执行这两件事?
没什么不同。您只需要确保您的脚本使用基于控制台的脚本主机cscript 运行。
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
还有一个选项可以防止在输出上显示横幅。
cscript //NoLogo myscript.vbs
输出:
test1 arg2
test2
重定向:
cscript //NoLogo myscript.vbs>output.txt
PS:cscript 是仅在 Windows Server 操作系统上的默认脚本解释器。否则默认为 wscript。因此,使用特定的脚本宿主运行脚本是一种很好的做法。
要更改默认脚本主机,请查看运行您的脚本
有用的链接:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句