JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

stdin

core-api


    core/file
    src/core/io.c on line 844, column 1

    The standard input file.


2 examplesSign in to add an example
Loading...
# Linux pipes | send data through stdin
# To make linux programs accepting varied input forms:

(defn main [_ & args]
  # If no arguments, read from stdin
  (let [data (if (empty? args) (file/read stdin :all) (string/join args " "))]
    (print (sum (flatten (parse-all data))))))

# This accepts: 1 2 3 or "1" "2" "3" or "1 2 3" or "[1 2 3]" besides piping data in
# janet fib.janet 5 | janet sum.janet

# Allow file inputs also:

(defn main [_ & args]
  (let [data (cond (empty? args) (file/read stdin :all)
                   (os/stat (first args)) (slurp (first args))
                   (string/join args " "))]
    (print (sum (flatten (parse-all data))))))
veqqqPlayground
# Interactively read a line from STDIN
(file/read stdin :line)

# Type abcd and then press ENTER
abcd

# Returns:
@"abcd\n"
semperosPlayground