Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to write a Win32 app that prompts for a 3 character input and stores it in a variable for later use. However, so far I've got it to spawn a new console, write my text to the console, and then it doesn't seem to be waiting for input. My Perl in a Nutshell book indicates the ReadChar call from Win32::Console should be able to read a certain number of characters from the console, but it doesn't seem to be pausing for this input. Below is the code. All advice appreciated.

Thanks,

Glenn

#!/usr/bin/perl use Win32::Console; $con = Win32::Console->new(); $con->Mode(ENABLE_WINDOW_INPUT,ENABLE_PROCESSED_INPUT,ENABLE_LINE_INPU +T,ENABLE_ECHO_INPUT,ENABLE_PROCESSED_OUTPUT,ENABLE_WRAP_AT_EOL_OUTPUT +); $con->Display; $con->Write("Please enter the agent ID number: "); # I want to wait fo +r input here, but apparently the ReadChar below doesn't do that @info = $con->Info(); $con->Write("The cursor info is ",$info[3],",",$info[4],". \r"); # Thi +s presently prints no cursor data $port = ($con->ReadChar(3,$info[3],$info[4])); $con->Write("The port number to use is ",$port);

Replies are listed 'Best First'.
Re: reading input from Win32 console
by japhy (Canon) on Aug 12, 2001 at 21:53 UTC
    You're misusing functions left and right. First, the Mode method requires a single argument; the modes must be ORed together:
    $con->Mode(ENABLE_WINDOW_INPUT | ENABLE_PROCESSED_INPUT);
    Next, the Write method takes a single argument (this is totally poor planning, I think). So you need to write things like:
    $con->Write("The cursor info is $info[3],$info[4].\n");
    And finally, the ReadChar method is for getting text that is already on the screen. You don't want that -- you want to get input from the user. To do that, I found that I can just read text normally:
    chomp(my $data = <STDIN>);

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: reading input from Win32 console
by ralphie (Friar) on Aug 13, 2001 at 16:19 UTC
    you might want to jump over to fatbrain or amazon or where ever and pick up a copy of dave roth's "win32 perl programming", and perhaps the newer "win32 perl scripting" as well. i pulled down my copy of the former and looked at the chapter concerning consoles and realized that you would be far better off reading the chapter yourself than having me synthesize a reply from the material.

    these books ,imho, represent a wealth of material on win32 perl programming. in fact, as i recall, the "win32 perl scripting" book got an extremely positive review in this community a few months back.