Ctrl-C with R.exe and Rterm.exe in R v1.9.0
-----Original Message----- From: r-devel-bounces@stat.math.ethz.ch [mailto:r-devel-bounces@stat.math.ethz.ch] On Behalf Of Duncan
Murdoch
Sent: den 6 maj 2004 16:16 To: Henrik Bengtsson Cc: r-devel@stat.math.ethz.ch Subject: Re: [Rd] Ctrl-C with R.exe and Rterm.exe in R v1.9.0 On Wed, 5 May 2004 12:57:29 +0200, "Henrik Bengtsson" <hb@maths.lth.se> wrote :
Ctrl-C works as expected. Exiting R and you're back at a "clean" prompt. Now, try the same thing with R.exe (from a restarted
prompt):
C:\Program Files\R>rw1090\bin\R.exe --vanilla --quiet
^C ^C 1+1
[1] 2
Sys.sleep(100)
^C C:\Program Files\R>
Strange things happen. R seems still to be running but has
at the same
time returned(?) the control back to the Command prompt.
Yes, that is indeed strange behaviour. Ctrl-C definitely presents problems. For instance, on my WinXP system running R from a Cygwin prompt, a Ctrl-C during the Sys.sleep kills Rterm, whereas under the Windows cmd.exe prompt it works properly as it did for you.
Cygwin is indeed where I noticed the problem first. For Cygwin, I know that Ctrl-C did not kill Rterm on R v1.7.1 and before, but from R v1.8.1 (don't know about R v1.8.0) it all of a sudden started to do it. Maybe there is a clue somewhere in the diff's between v1.7.1 and v1.8.x, which may also explain what is going on in R.exe and Rterm.exe.
I can guess at an explanation for what you saw, but I don't know how to fix it: - R (as opposed to Rterm) is a small .exe program that does a little argument parsing, then runs Rterm. It looks as though the Ctrl-C is going to R, and killing that process, but leaving the child process Rterm running. But since both Rterm and cmd.exe are reading and writing to standard file handles, you get the messed up prompts. I've just tried doing what the Windows documentation says should work (adding this line before Rterm is called: SetConsoleCtrlHandler(NULL, TRUE); /* Ignore Ctrl-C; Rterm will handle them */ but this didn't fix the problems, it just made them different (i.e. Ctrl-C stopped working completely). Rterm *does* set a Ctrl-C handler, but it just isn't being called, as far as I can
tell.
A simple workaround is to run Rterm or Rgui rather than R. If anyone knows a real fix, please let me know. Duncan Murdoch
By the way, nice job with R.exe together will Rtools. It makes it more convenient to work with R on both Windows and *nix. Thanks. Cheers Henrik Bengtsson