6

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'

enthus1ast
  • 2,099
  • 15
  • 22

3 Answers3

4

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

dom96
  • 1,012
  • 1
  • 9
  • 22
2
var f : File;
discard f.open(0, fmRead)

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

... works -- stdin has file handle 0

shaunc
  • 5,317
  • 4
  • 43
  • 58
  • gives me `foo.nims(2, 10) Error: attempting to call undeclared routine: 'open'` i'm on `Version 0.13.0` – enthus1ast May 14 '16 at 11:43
  • hmm ... I'm using that version too. For me it resolves to http://nim-lang.org/docs/system.html#open,File,FileHandle,FileMode (FileHandle is just cint) – shaunc May 16 '16 at 15:43
2

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).

Kaushal Modi
  • 1,258
  • 2
  • 20
  • 43
genotrance
  • 383
  • 2
  • 5