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

Dearest Monks,

The IO::Prompt module is currently failing on my Win2000 ActivePerl 5.8.8 system with the following error:
Cannot write to terminal: No such file or directory at scratch.pl line + 13
Ultimately, I'm attempting to create a couple of simple scripts in order to practice with the functionality of the Expect module. My first step was to create a script that would prompt for dummy STDIN interaction and quit with an "exit" command. In order to also try out the suggestion from "Perl Best Practices" Chapter 10 for using IO::Prompt, I came up with the following script:
use IO::Prompt; use strict; print <<'END_INTRO'; Mary had a little lamb Then the lamb ate Mary and it was little no more. END_INTRO my $choice = ''; while ($choice ne 'exit') { $choice = prompt "Prompt: ", -require => {"Prompt (requires a single word, exit to quit): " + => qr/^\w+$/}; print "You typed '$choice'\n"; }
The above code works fine on linux, but fails with the above error on my windows box. The DIAGNOSTICS section of the pod states this concerning the error:
Cannot write to terminal: %s
Cannot read from terminal: %s

prompt() attempted to access the terminal but couldn't. This may mean your environment has no /dev/tty available, in which case there isn't much you can do with this module. Sorry.
I have trouble imagining that this module was not intended for use with ActivePerl. Especially if it was suggested in the Best Practices Book. However, if this is the case, is there an alternative module that y'all would suggest?

Regards,
- Miller

Replies are listed 'Best First'.
Re: IO::Prompt - Cannot write to terminal
by syphilis (Archbishop) on Jul 21, 2007 at 01:30 UTC
    Hi wind,

    Neither Expect nor IO::Prompt work on Windows (though, faik, both may work under Cygwin.)

    Afaict, the ppm package exists because none of the tests fail. (Even the cpantesters report it as passing on Windows.) But the tests pass on Windows only because they don't actually test the functionality of the module ... I wonder how that trick rates under "Perl's Best Practices" :-)

    Win32::Console comes to mind as a possible replacement.

    Cheers,
    Rob
      Expect is reported to work on Cygwin but not on ActivePerl:

      Expect FAQ Can I use this module with ActivePerl on Windows?

      However, IO::Prompt says nothing about its usability on alternate systems. It has a list of DEPENDENCIES, all which install without error under ActivePerl along with the module itself. I definitely consider that very bad practice, and will send an email to the module maintainer suggestion that he at the very least add a FAQ entry.

      Thanks,
      - Miller

        The module makes no attempt at portability. It opens dev/tty unconditionally. You can get the prompt to display by changing the first few lines of sub prompt, but after that you are in a world of hurt.

        open $OUT, ($^O eq 'MSWin32' ) ? '>CON' : ">/dev/tty" or croak "Cannot write to terminal: $!" if !$OUT; $OUT->autoflush(1); @prompt = $flags{ -prompt } if !@prompt and $flags{ -prompt }; my $IN; if ($flags{-tty} || $flags{-argv}) { open $IN, ($^O eq 'MSWin32' ) ? '<CON' : ">/dev/tty" or croak "Cannot read from terminal: $!"; }

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: IO::Prompt - Cannot write to terminal
by BrowserUk (Patriarch) on Jul 21, 2007 at 02:10 UTC