Jump to content
Sign in to follow this  

(solved) Problems using ConsoleRead() to read input

Recommended Posts


I'm trying to make a command line utility that will read input from the console that it was called from, and write output back to the console.

I have the following code:

;Reads console input and outputs message box

ConsoleWrite("Please enter data:")
$console = ConsoleRead()
$buttoncode = MsgBox(2, "From console I read", $console)
If $buttoncode = 3 Then
    $button = "abort"
ElseIf $buttoncode = 4 Then
    $button = "retry"
ElseIf $buttoncode = 5 Then
    $button = "ignore"
ConsoleWrite(@CRLF & "The " & $button & " button was pressed in the Msgbox." & @CRLF)

When run from Scite it runs as expected. In the Output Pane at the bottom of Scite "Please enter data:" appears, any text typed within 6 seconds will appear in the Msgbox, and the pressed msgbox button will appear in the Output pane.

When compiled to an .exe, the program will accept input only if piped into it.

Echo test message | console.exe

If the program is just launched as console.exe, and keys are typed on the keyboard, the Msgbox will appear blank, and pressed keys are passed back to cmd when the script terminates.

Is there anyway to get ConsoleRead() to read keyboard input?

Edited by TurionAltec

Share this post

Link to post
Share on other sites

The command shell "DOS Box" is not a "console" in the meaning of ConsoleRead() and ConsoleWrite(). As you found, the console at the bottom of SciTE is a "console" for this purpose.

When you compile as a console (non-GUI) application, ConsoleRead() connects to STDIN and ConsoleWrite() connects to STDOUT. Now you can see ConsoleWrite() data through STDOUT show up on the "DOS Box", but what is typed in there does not go to STDIN for ConsoleRead() to see unless you ECHO it or pipe it there.

Confusing, ain't it?


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

So no way to easily link the keyboard input in a "DOS box" to STDIN?

Sigh, I guess I'll try a workaround like listening on a local TCP port and telneting in.

Share this post

Link to post
Share on other sites

Found a solution to this. Using FileOpen("con")


Got there from this post:


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this