CScript-在控制台上的同一条线上打印输出?
-
04-10-2019 - |
题
如果我有一个将线输出到屏幕上的CScript,则如何在每次打印后避免“线馈电”?
例子:
for a = 1 to 10
WScript.Print "."
REM (do something)
next
预期的输出应为:
..........
不是:
.
.
.
.
.
.
.
.
.
.
过去,我用来打印“ UP箭头字符” ASCII代码。可以在CScript中完成吗?
回答
在同一条线上打印,没有额外的CR/LF
for a=1 to 15
wscript.stdout.write a
wscript.stdout.write chr(13)
wscript.sleep 200
next
解决方案
利用 WScript.StdOut.Write()
代替 WScript.Print()
.
其他提示
WScript.Print()
打印一条线,您无法更改。如果您想在该行上有多个东西,请构建字符串并打印出来。
Dim s: s = ""
for a = 1 to 10
s = s & "."
REM (do something)
next
print s
只是直接地 cscript.exe
只是Windows脚本主机的命令行接口,而VBScript就是语言。
我在JavaScript中使用以下“日志”函数来支持WScript或CScript环境。如您所见,此功能只有在可能的情况下才会写入标准输出。
var ExampleApp = {
// Log output to console if available.
// NOTE: Script file has to be executed using "cscript.exe" for this to work.
log: function (text) {
try {
// Test if stdout is working.
WScript.stdout.WriteLine(text);
// stdout is working, reset this function to always output to stdout.
this.log = function (text) { WScript.stdout.WriteLine(text); };
} catch (er) {
// stdout is not working, reset this function to do nothing.
this.log = function () { };
}
},
Main: function () {
this.log("Hello world.");
this.log("Life is good.");
}
};
ExampleApp.Main();
不隶属于 StackOverflow