Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Prompting for input inside IDE run (was Reading from STDIN)

by haj (Vicar)
on Mar 27, 2023 at 07:22 UTC ( [id://11151246]=note: print w/replies, xml ) Need Help??


in reply to Prompting for input inside IDE run (was Reading from STDIN)

How do you run those programs inside emacs? I guess this is on Windows? Are you using Powershell as your shell-file-name?

One annoying effect I see on Windows is that STDOUT is buffered. So, if you're expecting a prompt, then you won't see it in time, but you can still enter your input line when the program seems to "hang". The w32 FAQ has a workaround for "Perl script buffering".

I could run the following program under M-x perldb and M-x eshell, and it behaves as I would expect:

use 5.028; # Turn all buffering off. select((select(STDOUT), $| = 1)[0]); select((select(STDERR), $| = 1)[0]); select((select(STDIN), $| = 1)[0]); print "Give me a cookie: "; my $thing = readline(STDIN); $thing =~ /^(a )?cookie$/ or die "That was no cookie.\n"; say "Thanks and goodbye!";

Replies are listed 'Best First'.
Re^2: Prompting for input inside IDE run (was Reading from STDIN)
by LanX (Saint) on Mar 27, 2023 at 12:45 UTC
    > How do you run those programs inside emacs? I guess this is on Windows?

    With mode-compile, which is not core, but nevertheless the default in cperl-mode.

    You may want to look into the perl menu in the top-bar after activating cperl-mode.

    <menu-bar> <Perl> <Run> runs the command mode-compile, which is an interactive autoloaded compiled Lisp function in `mode-compile.el'.

    Auto flush was helpful yes, but input is still ignored.

    Actually all input is considered compilation or error navigation commands, which makes sense in a buffer with start

    Now I'm thinking about making my script automatically redirecting stdout and stdin to a spawned console /or buffer. This while still keeping stder in the compilation buffer...

    I did this before in order to debug Term::ReadLine apps, have to dig that out again. I'm weak on tty Channel foo ...

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

      With mode-compile, which is no not core but the default in cperl-mode.

      That would have been helpful to know. That entry is disabled in my Emacs because I don't have mode-compile. Heck, that thing is pretty stale and can't be byte-compiled nor M-x eval-buffered in Emacs 27...

      Anyway, mode-compile is the culprit. Contrary to its name, it runs the program, using a mechanism which does not make STDIN of the Perl process available to you.

      What you could do is wrap the following lisp snippet into a command which suits you:

      (compile "perl your_script.pl" t)

      Replacing the program name perl and script name your_script.pl by variables is left as an exercise to the reader. The t parameter does the trick to give you what Emacs calls a "comint" environment. So, you end up in a buffer *compilation* in compilation-mode with "clickable" error messages, but the buffer is not read-only, you can just enter text after the prompt.

        > (compile "perl your_script.pl" t)

        Yes, thanks, I already figured this out in the meantime.

        > variables is left as an exercise to the reader.

        That's one of the things mode-compile does for me (and is expected from an IDE nowadays)

        I will try to find a way to patch/configure mode-compile accordingly.

        Cheers Rolf
        (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11151246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found