首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >lz4命令意外地输出到stdout

lz4命令意外地输出到stdout
EN

Ask Ubuntu用户
提问于 2021-03-10 12:26:14
回答 1查看 570关注 0票数 5

使用这个lz4命令:

代码语言:javascript
复制
$ apt search ^lz4$
Sorting... Done
Full Text Search... Done
lz4/focal,now 1.9.2-2 amd64 [installed,automatic]
  Fast LZ compression algorithm library - tool

$ lz4 --version
*** LZ4 command line interface 64-bits v1.9.2, by Yann Collet ***

这个命令通常创建一个filename.lz4文件(就像gzip一样):

代码语言:javascript
复制
$ lz4 -9 -k filename

但是,这个命令没有,而是在我没有告诉它时写到stdout:

代码语言:javascript
复制
$ t=$(lz4 -9 -k filename)
Warning : using stdout as default output. Do not rely on this behavior: use explicit `-c` instead ! 
bash: warning: command substitution: ignored null byte in input

它为什么要这么做?它是一个bug,还是有什么原因被记录在某个地方?

EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2021-03-10 13:31:48

这种行为似乎是一个特征,而不是一个bug。除了在源代码中,我在任何地方都找不到文档:

代码语言:javascript
复制
/* No output filename ==> try to select one automatically (when possible) */
while ((!output_filename) && (multiple_inputs==0)) {
    if (!IS_CONSOLE(stdout)) {
        /* Default to stdout whenever stdout is not the console.
         * Note : this policy may change in the future, therefore don't rely on it !
         * To ensure `stdout` is explicitly selected, use `-c` command flag.
         * Conversely, to ensure output will not become `stdout`, use `-m` command flag */
        DISPLAYLEVEL(1, "Warning : using stdout as default output. Do not rely on this behavior: use explicit `-c` instead ! \n");
        output_filename=stdoutmark;
        break;
        .
        .
}

在Linux上,IS_CONSOLE使用isatty来确定文件desscriptors是否连接到终端。

正如注释中所建议的,在没有tty的情况下,可以使用-m选项强制生成输出文件:

代码语言:javascript
复制
t=$(lz4 -9 -k -m filename)
票数 4
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1322528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档