Skip to content

Ctrl-C with R.exe and Rterm.exe in R v1.9.0

5 messages · Henrik Bengtsson, Brian Ripley, Duncan Murdoch

#
Hi, I'm running R v1.9.0 on WinXP Pro. I noticed that R.exe and
Rterm.exe behave differently on Ctrl-C. Starting a Windows Command
prompt (cmd.exe) you get from running Rterm.exe:

C:\Program Files\R>rw1090\bin\Rterm.exe --vanilla --quiet
[1] 2
[1] 2
C:\Program Files\R>
C:\Program Files\R>

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
[1] 2
^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. Try to
continue by pressing ENTER and/or type 1 + ENTER, 2 + ENTER etc and
you'll see that eventually you get replied from R also:
'1+1' is not recognized as an internal or external command,
operable program or batch file.

C:\Program Files\R>1+1
'+1' is not recognized as an internal or external command,
operable program or batch file.

C:\Program Files\R>q
C:\Program Files\R>
function (save = "default", status = 0, runLast = TRUE)
.Internal(quit(save, status, runLast))
<environment: namespace:base>
Clearly both cmd.exe and R is trying to parse the stdin. Some
keystrokes goes to R and some to cmd.exe.

Best wishes

Henrik Bengtsson

Div. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden 
(Sweden +2h UTC, Melbourne +10 UTC, Calif. -7h UTC)
+46 708 909208 (cell), +46 46 320 820 (home), 
+1 (508) 464 6644 (global fax),
+46 46 2229611 (off), +46 46 2224623 (dept. fax)
h b @ m a t h s . l t h . s e, http://www.maths.lth.se/~hb/
1 day later
#
On Wed, 5 May 2004 12:57:29 +0200, "Henrik Bengtsson"
<hb@maths.lth.se> wrote :
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.

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
#
Murdoch
prompt):
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.
tell.
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
#
On Thu, 6 May 2004, Henrik Bengtsson wrote:

            
No, as it was to do with a change in the MinGW runtime system and not in 
R.

Expecting to be able to use ^C as a Windows signal in a shell that is 
emulating Unix is I think unrealistic.  ^C in Rterm does work in tcsh.exe, 
cmd.exe and various clones.

It is becoming a mantra, but

  *** Cygwin is not Windows ***

and R is a Windows and not Cygwin executable.  People who want a Cygwin 
port of R perhaps should work on one ....
#
On Thu, 6 May 2004 17:01:09 +0100 (BST), Prof Brian Ripley
<ripley@stats.ox.ac.uk> wrote:

            
Yes, but there's still a bug if Rterm.exe was started by R.exe in
cmd.exe.   It's just not one that I know how to fix.

Duncan