cscript - 在控制台的同一行上打印输出?

发布于 2024-09-02 12:33:44 字数 486 浏览 5 评论 0原文

如果我有一个将行输出到屏幕的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半透明的墙 2024-09-09 12:33:45

使用 WScript.StdOut.Write() 而不是 WScript.Print()

Use WScript.StdOut.Write() instead of WScript.Print().

魄砕の薆 2024-09-09 12:33:45

WScript.Print() 打印一行,您无法更改它。如果您想在该行上包含多个内容,请构建一个字符串并打印它。

Dim s: s = ""

for a = 1 to 10
  s = s & "."
  REM (do something)
next

print s

简单地说,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.

Dim s: s = ""

for a = 1 to 10
  s = s & "."
  REM (do something)
next

print s

Just to put that straight, cscript.exe is just the command line interface for the Windows Script Host, and VBScript is the language.

—━☆沉默づ 2024-09-09 12:33:45

我在 JavaScript 中使用以下“log”函数来支持 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();

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.

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文