VBScript의 출력을 메모장/워드 패드에 실시간으로 작성하고 싶습니다. 이 작업을 수행하는 가장 좋은 방법은 무엇입니까? 나는 sendkeys를 알고 있지만, 특수 명령에 대한 입력을 구문 분석해야한다.VBScript to Notepad/Wordpad
1
A
답변
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
왜 파일 시스템 개체를 사용하여 텍스트 스트림을 만들지 않습니까? – Fionnuala
특수 문자를 구문 분석하는 것은 실제로 로켓츠가 아닙니다. Regex.Replace (myString, "([\ $ \^\ % \ ~ \ {\} \ [\] \ (\)])", "{$ 1}")와 같은 정규 표현식을 사용하면 트릭을 수행해야합니다. 어쩌면 당신은'Regex.Replace (myString, "\ t", "{TAB}")'와'Regex.Replace (myString, \ r \ n ","{ENTER} ")'. 다른 모든 특수 입력은'{SHIFT} ','{F1} '등과 같은 키보드 입력이기 때문에 이것들을 교체해야하는 유일한 문자입니다. – AutomatedChaos