How to read from the stdin with nim script?
Asked Answered
C

3

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'

Crossstaff answered 19/3, 2016 at 15:15 Comment(0)
P
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

Prager answered 19/3, 2016 at 15:30 Comment(0)
R
2
var f : File;
discard f.open(0, fmRead)

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

... works -- stdin has file handle 0

Redfaced answered 29/4, 2016 at 15:17 Comment(2)
gives me foo.nims(2, 10) Error: attempting to call undeclared routine: 'open' i'm on Version 0.13.0Crossstaff
hmm ... I'm using that version too. For me it resolves to nim-lang.org/docs/system.html#open,File,FileHandle,FileMode (FileHandle is just cint)Redfaced
T
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).

Totalizator answered 14/1, 2019 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.