我有一段代码提示用户输入,并在
Windows中运行代码时完美地工作.但是,在
Linux中,它执行每一行而不等待用户输入.
我已将代码添加到单独的函数中并使用系统(“stty -echo”)但未成功.
为什么会发生这种情况,可以做些什么?
(执行命令:Rscript test.R)
require(Biostrings) read_value <- function(prompt_text = "",prompt_suffix = getOption("prompt"),coerce_to= "character") { prompt <- paste(prompt_text,prompt_suffix) system("stty -echo") as(readline(prompt),coerce_to) } prints<-function() { opt<-as.character(readline(prompt = "Enter parameter values: ")) system("stty -echo") i<-1 while ((i<=5)) { if (i==1) { expr.filename <- as.character(readline(prompt = "Expression file name: ")) tryCatch( {expr.file<-read.table(expr.filename)},error=function(e) {print("ERROR : Enter valid filename!") return }) } if (i==2) { system("stty -echo") fasta.filename <- as.character(readline(prompt = "Fasta file name: ")) tryCatch( {sequence_data<-read.DNAStringSet(fasta.filename)},error=function(e) {print("ERROR : Enter valid filename!") return }) } #missing piece of code i<-i+1 }