2010-05-24 119 views
7

如果我有一個cscript輸出行到屏幕上,每次打印後如何避免「換行」?cscript - 在控制檯的同一行上打印輸出?

例子:

for a = 1 to 10 
    WScript.Print "." 
    REM (do something) 
next 

預期輸出應該是:

.......... 

不:

. 
. 
. 
. 
. 
. 
. 
. 
. 
. 

在過去,我已經用打印的 「向上箭頭人物」 ASCII碼。這可以在cscript中完成嗎?

ANSWER

打印在同一行,沒有額外的CR/LF

for a=1 to 15 
    wscript.stdout.write a 
    wscript.stdout.write chr(13) 
    wscript.sleep 200 
next 

回答

9

使用wscript.stdout.write()而不是打印。

+0

oops - 註冊我的VB日子。是的,WScript.Print是正確的命令! – Guy 2010-05-24 14:57:05

+1

我的意思是你可以使用wscript.stdout.write而不是wscript.print在同一行上打印而不需要換行符。 – naivnomore 2010-05-25 17:17:50

+0

是的 - 這將工作! – Guy 2010-06-10 22:03:38

2

WScript.Print()打印一條線,你不能改變的。如果你想在該行有多個事物,建立一個字符串並打印。

Dim s: s = "" 

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

print s 

只是把那個直,cscript.exe只是在命令行的Windows腳本宿主接口,和VBScript是語言。

+0

是,wscript.print是正確的 - 迴歸到我的舊的VB腳本天...... 我敢肯定,你知道你可以在「回聲」命令字符到控制檯,這是你如何寫的老「DOS」風格的應用程序。這仍然可以完成操縱光標? – Guy 2010-05-24 15:01:15

+0

@Guy:VBScript的'WScript.Print()'就像VB6的'Debug.Print()',就換行而言,所以......不,據我所知。 – Tomalak 2010-05-24 15:56:46

-1

我在我的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(); 
+0

這並沒有回答這個問題('每次打印後如何避免「換行」?) – Helen 2012-12-06 15:10:41