英文:
How to process lines from external process in elvish?
问题
我想从某个过程生成的字符串行中提取信息。可以通过逐行处理这些行来完成。提取的数据应保存在几个集合中(列表?映射?等等...)
要处理的行是特定的,可以忽略它们,直到找到某个特定的行。然后应保存所有随后的行,然后进行处理。
我在使用Elvish时遇到的问题是,我不知道如何将生成的输出行转换为字符串列表。
我尝试过:
var lines = (my_app) | from-lines
但Elvish说右边有多个值,而左边只有一个值(无法从这些值中创建列表)。
我尝试的另一种方法是:
var data = []
my_app | each {|line|
...
set data = conj $data $line
}
但它也不起作用(尽管我不记得错误消息)。此外,(conj $data $line)
也不起作用:Elvish将其视为无法找到的外部命令。
英文:
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
得分: 0
简单的输出捕获对我很有效:
~> cat t.txt
a
b
~> var linelist = [( cat t.txt )]
~> put $linelist[1]
▶ b
英文:
Quite simple Output capture worked for me:
~> cat t.txt
a
b
~> var linelist = [( cat t.txt )]
~> put $linelist[1]
▶ b
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论