How to process lines from external process in elvish?

59 Views Asked by At

Original problem: I want to extract information from (string) lines, produced by some process. It can be done by processing the lines one by one. Extracted data should be saved in several collections (lists? maps? whatever...)

The lines to process are specific, and they can be ignored, until some specific line is found. All the following lines should be saved, and then processed.

My problem with elvish is that I don't know, how to transform the produced output lines into a list of strings.

I have tried:

var lines = (my_app) | from-lines`

but elvish says, that on the right side there are many values, and on the left side is only one (it cannot make a list from those values).

My other approach was:

var data = []
my_app | each {|line|
  ...
  set data = conj $data $line
}

but it also didn't work (I don't remember the error message, though). Also, (conj $data $line) doesn't work: elvish treats it as some external command, which cannot be found.

1

There are 1 best solutions below

2
On BEST ANSWER

Quite simple Output capture worked for me:

~> cat t.txt
a
b

~> var linelist = [( cat t.txt )]

~> put $linelist[1]
▶ b