Send String to Console
Posted: Fri Apr 02, 2010 11:51 pm
Hi all, a little while ago I needed a way to send a string of text to a console window on Windows. I failed miserably at it.
But, after coming across the old project I decided to give it another shot and it turned out great(Yay for the Survival Guide and Kale's Guide!) for my own use. Maybe someone could benefit from this.
I figure since I'm always asking for help here I could *try* and contribute! 
It probably doesn't look pretty, but it works.
But, after coming across the old project I decided to give it another shot and it turned out great(Yay for the Survival Guide and Kale's Guide!) for my own use. Maybe someone could benefit from this.


It probably doesn't look pretty, but it works.

Code: Select all
Global hInput
Procedure SendConsole(szText.s)
szLength = Len(szText.s)
For sz = 0 To szLength+1
szCharacter$ = Mid(szText.s,sz+1,1)
szLetterByLetter=Asc(szCharacter$)
PostMessage_(hInput,#WM_CHAR,szLetterByLetter,0)
Next
PostMessage_(hInput,#WM_CHAR,13,0)
EndProcedure
hInput = FindWindow_(0,"Administrator: c:\Windows\system32\cmd.exe")
If hInput = 0
Debug "Error, command prompt not open or string mismatch!"
Else
SendConsole("echo Hello world!! This is a string, I think? What about numbers? 1+1=393")
EndIf