VBScript в Блокнот / Wordpad - PullRequest
       54

VBScript в Блокнот / Wordpad

1 голос
/ 22 февраля 2012

Я хотел бы записать вывод из VBScript в блокнот / WordPad в режиме реального времени.Какой лучший способ сделать это?Я знаю о sendkeys, но он требует, чтобы я проанализировал ввод для специальных команд.

Ответы [ 2 ]

2 голосов
/ 23 февраля 2012

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 голос
/ 22 февраля 2012

Попробуйте это

 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
...