Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read from the stdin with nim script?

Tags:

nim-lang

How would i read from the stdin via nimscript?

i've tried:

if readLine(stdin) == "yes":
  exec buildCommand  

i've run the script with

nim c build.nims

i receive

build.nims(50, 13) Error: undeclared identifier: 'stdin'

like image 844
enthus1ast Avatar asked Mar 19 '16 15:03

enthus1ast


3 Answers

I don't think nimscript supports reading from stdin just yet.

You might want to create a feature request for this: https://github.com/nim-lang/Nim/issues

like image 97
dom96 Avatar answered Oct 19 '22 19:10

dom96


var f : File;
discard f.open(0, fmRead)

let s = f.readLine()
echo "INPUT " & s

... works -- stdin has file handle 0

like image 2
shaunc Avatar answered Oct 19 '22 19:10

shaunc


This is now implemented in nimscript in devel: readAllFromStdin().

It will be available in Nim v0.20.0+ (yet to be released as of 2019-05-21).

like image 2
genotrance Avatar answered Oct 19 '22 19:10

genotrance