cscript - 在控制台的同一行上打印输出?
如果我有一个将行输出到屏幕的 cscript,如何避免每次打印后的“换行”?
示例:
for a = 1 to 10
WScript.Print "."
REM (do something)
next
预期的输出应该是:
..........
不:
.
.
.
.
.
.
.
.
.
.
过去我曾经打印“向上箭头字符”ASCII 代码。这可以在cscript中完成吗?
答案
在同一行上打印,无需额外的 CR/LF
for a=1 to 15
wscript.stdout.write a
wscript.stdout.write chr(13)
wscript.sleep 200
next
If I have a cscript that outputs lines to the screen, how do I avoid the "line feed" after each print?
Example:
for a = 1 to 10
WScript.Print "."
REM (do something)
next
The expected output should be:
..........
Not:
.
.
.
.
.
.
.
.
.
.
In the past I've used to print the "up arrow character" ASCII code. Can this be done in cscript?
ANSWER
Print on the same line, without the extra CR/LF
for a=1 to 15
wscript.stdout.write a
wscript.stdout.write chr(13)
wscript.sleep 200
next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
WScript.StdOut.Write()
而不是WScript.Print()
。Use
WScript.StdOut.Write()
instead ofWScript.Print()
.WScript.Print()
打印一行,您无法更改它。如果您想在该行上包含多个内容,请构建一个字符串并打印它。简单地说,
cscript.exe
只是 Windows Script Host 的命令行界面,而 VBScript 是语言。WScript.Print()
prints a line, and you cannot change that. If you want to have more than one thing on that line, build a string and print that.Just to put that straight,
cscript.exe
is just the command line interface for the Windows Script Host, and VBScript is the language.我在 JavaScript 中使用以下“log”函数来支持 wscript 或 cscript 环境。正如您所看到的,只有在可以的情况下,该函数才会写入标准输出。
I use the following "log" function in my JavaScript to support either wscript or cscript environment. As you can see this function will write to standard output only if it can.