linux - cat命令能够读取的文本长度是否存在限制?
PHPz
PHPz 2017-04-17 11:49:22
0
1
814

我用cat命令分行读取js文件,将其中内容传递给mongo时,如果单行文本过长,则往往会出现“unexpected identifier"之类的错误,但是用mongo直接处理js文件时则没有这类问题。

PHPz
PHPz

学习是最好的投资!

reply all(1)
PHPzhong

cat There is no limit to the length of text that can be read. And cat (the default parameter) doesn't care how many lines the file has; it just keeps copying the data.

The problem is with the linenoise library used by mongo shell. At <mongo>/shell/linenoise.cpp:2541 (different versions may differ), if the data is not obtained from the terminal, linenoise always fetches up to 4096 bytes per line (UTF-8), so mongo reads the broken lines (linsenoise simply Didn't consider it breaking some lines by doing so; maybe they simply didn't test it for non-interactive use).

As for reading from the terminal, it uses another set of logic. When I tried to put in a super long line of 4100 characters, it just kept blinking and blinking and nothing came of it. I don’t know if there is a problem with this part, but I can’t test it anyway. The questioner might try typing the super long line directly.

I tried readline (Python) and everything works fine, even very long lines can be entered relatively easily and parsed correctly. Of course, zsh and bash, which often read scripts from pipes, will handle these situations well.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template