Subject: Re: NT Emacs, ^C in subshell

From: Lorenz Huelsbergen <[email-masked]>
Date: Mon, 27 Jan 1997 10:15:03 -0500

Hi Geoff.

Thanks for the ^C subshell info.  Got SML/NJ working with (C-c C-c) 
as ^break over the weekend.  Two more related things:

	1) ^C behavior (when implemented as ^break) is a bit different 
	   than under the DOS shell.  For example, if a program is
           doing a ReadFile from stdin, the ^C will interrupt the
	   ReadFile, but will not make it fail until it sees eol.
	   Under the DOS shell, this read would be going through 
	   ReadConsole, which seems to force the read to fail on ^C.
	   Not sure if this is because it's getting a ^break or using
	   ReadConsole.

	2) (C-c C-d) sends eof but seems to do so by closing the handle
	   associated with stdin.  When sent to a program running in 
	   the shell, the program sees eof (or, more precisely, a 
	   broken pipe) but then the shell itself terminates abnormally
	   (because, I think, stdin is no longer there).  Here's a 
	   program that illustrates:

#include <windows.h>
#include <stdio.h>

main(int argc,char *argv[])
{
  HANDLE h;
  BOOL flag;
  char buf[100];
  int dummy;
  
  h = GetStdHandle(STD_INPUT_HANDLE);
  flag = ReadFile(h,&buf,10,&dummy,NULL);
  if (!flag) {
    fprintf(stderr,"last error: %d\n",GetLastError());
  }
}

	   Run this in the Emacs subshell and send it a C-c C-d when
	   it's sitting in the ReadFile.  I don't think the shell should
	   terminate.

These are minor points;  thanks for helping me get ^C working.

Lorenz

>When I have Emacs generate a ctrl-c for the subprocess, the ctrl-c is
>not propagated to the subprocess.  However, if instead I have Emacs
>generate a ctrl-break for the subprocess (which is what is currently
>in 19.34), the subprocess sees the ctrl-break.  I do not understand
>why the ctrl-break is propagated but the ctrl-c is not.
>
>Unfortunately, I do not have much more time to fiddle with this right
>now.  A work around on your end until I am able to fix this would be
>to have your ctrl-c handler also be your ctrl-break handler.  This way
>you will see ctrl-c's in Emacs as ctrl-break's and handle them
>appropriately.
>
>-geoff
>
>Lorenz Huelsbergen writes:
>> 
>> 
>> Geoff, 
>> 
>> >Yes, it looks like Emacs is not passing the ctrl-c on to the
>> >subprocess correctly.  It defaults to terminating the process, so I
>> >need to add another case statement.
>> >
>> >Thanks,
>> >-geoff
>> 
>> Great.  when you have a version with this working, 
>> we'd be happy to test it for you.
>> 
>> Lorenz
>> 
>> >
>> >> First, thanks very much for having done the NT Emacs port and 
>> >> maintaining it.  It's a key piece in the (seemly inevitable)
>> >> transition from Unix to WindowsX that many will have to make.
>> >> 
>> >> Second, I'm having trouble with subshells and have checked the
>> >> faq but haven't found this specific problem.  We have an interactive
>> >> language (SML/NJ) that people frequently run as an Emacs shell.
>> >> It resets the ^C handler so that a non-terminating expression
>> >> can be interrupted, for example.  This doesn't seem to work 
>> >> in NT Emacs where the ^C exits the program.  My experiments to
>> >> date indicate that the ^C is never handed to SML/NJ's custom
>> >> ^C handler.  Is this indeed the case?  
>> >> 
>> >> Thanks.
>> >> 
>> >> Lorenz
>> >