Re: vbscript CSCRIPT howto : writie to screen and read from keyboard ?
Paul <[email protected]> Sat, 13 Dec 2025 17:14:13 -0500
| Newsgroups | alt.comp.lang.vbscript,alt.comp.os.windows-xp,alt.windows7.general |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On Sat, 12/13/2025 4:55 PM, Paul wrote:
> On Sat, 12/13/2025 11:51 AM, R.Wieser wrote:
>> Mr. Man-wai Chang,
>>
>>> https://www.google.com/search?q=vbscript+OpenTextFile+CreateTextFile+console{snip}
>>
>> [quote=me]
>> I can't get those to work using OpenTextFile / CreateTextFile.
>> [/quote]
>>
>> And yes, I did search for the solution before posting here. Alas, no dice.
>>
>> Regards,
>> Rudy Wieser
>>
>>
>
> I asked CoPilot to write me something.
>
> Prepare a vbscript CSCRIPT program which opens a window,
> accepts text input from the terminal session, then displays
> "You typed " followed by the text string, placing the text
> string on CONOUT and within the opened window, then waits
> for an additional carriage return to exit the program.
CoPilot actually commented at the end of the response, about the
missing non-blocking part. Why it didn't do this in the first place,
I don't know. Notice that the GUI now, isn't what you envisioned.
But at least the program "meets specification" from an "intentions
point of view". I don't know if this works for you though.
What is the "GOTO 0" thing ? I don't see a magic label, so this
might be a hallucination of some sort.
*******************************************************************
' Save as input_echo3.vbs
' Run with: cscript //nologo input_echo3.vbs
Option Explicit
Dim WshShell, userInput, dummy, htmlFile, fso, ts
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
' Prompt for input from terminal
WScript.StdOut.Write "Type something: "
userInput = WScript.StdIn.ReadLine
' Echo to console
WScript.StdOut.WriteLine "You typed " & userInput
' Create a temporary HTML file for the window
htmlFile = fso.GetSpecialFolder(2) & "\input_echo.html" ' Temp folder
Set ts = fso.CreateTextFile(htmlFile, True)
ts.WriteLine "<html><head><title>Input Echo</title></head>"
ts.WriteLine "<body style='display:flex;align-items:center;justify-content:center;"
ts.WriteLine "height:100%;font-family:sans-serif;font-size:16pt;'>"
ts.WriteLine "You typed <b>" & Replace(userInput,"'","'") & "</b>"
ts.WriteLine "<script>"
ts.WriteLine "window.name='EchoWin';"
ts.WriteLine "</script>"
ts.WriteLine "</body></html>"
ts.Close
' Launch mshta to show the window
WshShell.Run "mshta.exe """ & htmlFile & """", 1, False
' Wait for carriage return before exit
WScript.StdOut.Write "Press ENTER to exit..."
dummy = WScript.StdIn.ReadLine
' Close the window by sending a command to mshta
On Error Resume Next
WshShell.AppActivate "Input Echo"
WshShell.SendKeys "%{F4}" ' Alt+F4 to close
On Error GoTo 0
' Clean up temp file
On Error Resume Next
fso.DeleteFile htmlFile
On Error GoTo 0
*******************************************************************
Paul