bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19643: 24.2; shell mode


From: Eli Zaretskii
Subject: bug#19643: 24.2; shell mode
Date: Wed, 21 Jan 2015 17:49:54 +0200

> From: address@hidden
> Date: Tue, 20 Jan 2015 17:12:31 -0700
> 
> I'm trying to use shell mode.  In fact, I'm trying to run a Perl
> program in shell mode.  I launch the program, and it runs.  Input from
> a file is read, processed.  Output (to STDOUT) is printed to *shell*.
> Trouble is I can't read keyboard input (as in <STDIN>).  What am I
> missing (except a brain)?
> 
> Ok, this is Emacs 24.2.1 running on Windows XP.
> 
> I downloaded Perl from ActiveState in 2011.  Here's a simple Perl
> program that demos the problem:
> 
> print "Give me a number: ";
> chomp ( $Anumber = <STDIN> );
> print "Give me another: ";
> chomp ( $Bnumber = <STDIN> );
> $product = $Anumber * $Bnumber;
> print "$Anumber times $Bnumber = $product\n";
> 
> It works fine in a DOS window.  In emacs shell mode it tells me this
> 
> Use of uninitialized value $Anumber in chomp at c:\Perl\ex2-4.pl line 3.
> Use of uninitialized value $Bnumber in chomp at c:\Perl\ex2-4.pl line 5.
> Use of uninitialized value $Bnumber in multiplication (*) at c:\Perl\ex2-4.pl 
> line 6.
> Use of uninitialized value $Anumber in multiplication (*) at c:\Perl\ex2-4.pl 
> line 6.
> Use of uninitialized value $Anumber in concatenation (.) or string at 
> c:\Perl\ex2-4.pl line 7.
> Use of uninitialized value $Bnumber in concatenation (.) or string at 
> c:\Perl\ex2-4.pl line 7.
> Give me a number: Give me another:  times  = 0
> 
> Perl is complaining about uninitialized values before it has even
> printed the prompts for them.

It's a buffering issue.  On Windows, sub-processes are run via pipes,
and Perl evidently fully buffers its stdout when it's connected to a
pipe (as opposed to a console, where it is line-buffered, and is also
flushed when your script reads from STDIN).  There's nothing Emacs can
do about this, because the decision about the buffering mode is made
by the Perl interpreter.

Some interpreters, like Python, have a command-line switch to turn off
buffering, but Perl doesn't (AFAIK).  So you need to do that from your
Perl scripts.

My Perl is exceedingly rudimentary, but I found the solution here:

  http://perl.plover.com/FAQs/Buffering.html
  http://www.perlmonks.org/?node_id=280025

The solution is to add this single line at the beginning of your Perl
script:

  $|++;

This causes STDOUT to auto-flush after each output.

(There's also an alternative that needs to use the FileHandle module,
see the first URL above.)

Bottom line: I don't think this is an Emacs problem.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]