2012-02-22 17 views
1

VBScriptの出力をメモ帳/ワードパッドにリアルタイムで書きたいと思います。これを行う最善の方法は何ですか?私はsendkeysを認識していますが、特殊なコマンドの入力を解析する必要があります。VBScript to Notepad/Wordpad

+0

なぜファイルシステムオブジェクトを使用してテキストストリームを作成してみませんか? – Fionnuala

+1

特殊文字の解析は本当にロケット科学ではありません。 'Regex.Replace(myString) '([\ + \^\%\〜\ {\} \ [\] \(\)])"、 "{$ 1}")のような正規表現を使用すると、 'Regex.Replace(myString、" \ t "、" {TAB} ")と' Regex.Replace(myString、 ")のようになる' Tab'と 'Newline'文字を置き換えたいと思うかもしれません。 \ r \ n "、" {ENTER} ")'。他のすべての特殊入力は '{SHIFT}'、 '{F1}'などのキーボード入力であるため、これを置き換える必要があるのは唯一の文字です。 – AutomatedChaos

答えて

2

のSendKeysを試してみてはリアルタイムでサードパーティのアプリケーションに書き込むための唯一の方法です。なぜ、CScriptを使用せず、代わりに標準出力に書き込むのですか?それがそれが意味するものです。

' Force the script to run in the CScript engine 
If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then 
    strPath = WScript.ScriptFullName 
    strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34) 
    CreateObject("WScript.Shell").Run(strCommand) 
    WScript.Quit 
End If 

For i = 1 to 10 
    For j = 0 to 25 
    WScript.StdOut.WriteLine String(j, " ") & "." 
    WScript.Sleep 50 
    Next 

    For j = 24 to 1 Step - 1 
    WScript.StdOut.WriteLine String(j, " ") & "." 
    WScript.Sleep 50 
    Next 
Next 
1

この

Const fsoForWriting = 2 

    Dim objFSO 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 

    'Open the text file 
    Dim objTextStream 
    Set objTextStream = objFSO.OpenTextFile("C:\SomeFile.txt", fsoForWriting, True) 

    'Display the contents of the text file 
    objTextStream.WriteLine "Hello, World!" 

    'Close the file and clean up 
    objTextStream.Close 
    Set objTextStream = Nothing 
    Set objFSO = Nothing