# RinWIN: Character eaten by cmd or Powershell? R.exe or Rterm.exe?

August 6, 2007
By

(This article was first published on B.I.S. dato, and kindly contributed to R-bloggers)

Problem Description: When running R2.6.0(built with MinGW) in PowerShell (PS> /bin/R.exe), one can exit the running code with CTRL-C. However, the following situation is rather cratchy : the shell would (almost always) consequently omit the first character you type (for example, ls becomes "s" and hence is not recognized by shell anymore).

In the cmd.exe shell the same problem exists.

When I tried to start R again , the same problem is still there, some characters typed are "eaten" and all turn into a mess.

Explanation/Reason:

http://tolstoy.newcastle.edu.au/R/devel/04a/1055.html
Yes, that is indeed strange behaviour. Ctrl-C definitely presents problems.  For instance, on my WinXP systemrunning R from a Cygwin prompt, a Ctrl-C during the Sys.sleep killsRterm, whereas under the Windows cmd.exe prompt it works properly asit did for you.I can guess at an explanation for what you saw, but I don't know howto fix it:- R (as opposed to Rterm) is a small .exe program that does a littleargument parsing, then runs Rterm.  It looks as though the Ctrl-C isgoing to R, and killing that process, but leaving the child processRterm running.  But since both Rterm and cmd.exe are reading andwriting 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 willhandle 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-Chandler, 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 anyoneknows a real fix, please let me know.Duncan Murdoch