Skip to content
Prev 80117 / 398502 Next

readline() and Rterm in Windows

Mikkel Grum wrote:
It won't work so simply.  You're redirecting stdin, so user input would 
be taken from there; you're redirecting stdout and stderr, so the prompt 
won't be visible to the user.

You need to open new handles to the console.  The code below will do it 
in Windows; the syntax to specify the console in Unix-alikes will be 
different (but I don't know what it is).

conout <- file('CONOUT$','w')
conin <- file('CONIN$', 'r')
cat('Please enter an ID:', file=conout)
flush(conout)
id <- readLines(conin, 1)
print(id)

Duncan Murdoch