简体   繁体   English

嵌入式 Linux:无 output 从标准输出定向到文件或 FIFO 的日期开始

[英]Embedded Linux: No output from date when stdout directed to file or FIFO

I am trying to pass the date into a file eg:我正在尝试将日期传递到文件中,例如:

/pwd # date > file.txt

but every time I check the file, nothing is printed in there.但是每次我检查文件时,那里都没有打印任何内容。 I have tried other variants as well eg:我也尝试过其他变体,例如:

/pwd # echo "$(date)" > file.txt

/pwd # echo "$(/bin/date)" > /full/path/file.txt

/pwd # echo "$(/bin/date)" >> /full/path/file.txt (I wouldn't expect appending to make a difference but tried anyway) /pwd # echo "$(/bin/date)" >> /full/path/file.txt (我不希望附加会有所作为,但还是尝试了)

I thought well maybe it was some sort of permissions issue with date being able to access the file so, for kicks, I tried:我想也许这是date能够访问文件的某种权限问题,所以,为了踢球,我尝试了:

/pwd # sudo date > /full/path/file.txt

Attempting to store the date to bash variable is futile as well.尝试将日期存储到 bash 变量也是徒劳的。 But, sure enough, the date command by itself continues to work:但是,果然, date命令本身继续工作:

Mon Apr 5 14:16:26 UTC 2021

Anyone have any ideas what could be happening?有人知道会发生什么吗? According to every other post I've read, the things I am trying should be working.根据我读过的所有其他帖子,我正在尝试的事情应该是有效的。

Note this is a special (proprietary) kernel ( uname -a ):请注意,这是一个特殊的(专有)kernel( uname -a ):

在此处输入图像描述

However it's built on Debian so I would expect it to work.但是它建立在 Debian 上,所以我希望它能够工作。

EDIT: type date :编辑: type date

date is a tracked alias for /bin/date

Nothing interesting happens when prefixing command with set -x other than the tracking I see when running the command:除了我在运行命令时看到的跟踪之外,使用set -x为命令添加前缀时没有任何有趣的事情发生:

在此处输入图像描述

strace looks like it has some good information but I won't pretend to know how to interpret it: strace看起来有一些很好的信息,但我不会假装知道如何解释它:

在此处输入图像描述

EDIT 2:编辑2: 在此处输入图像描述

在此处输入图像描述

This is an unusual situation -- from the strace results, it looks like either a libc bug or a busybox problem.这是一种不寻常的情况——从 strace 结果来看,它看起来像是 libc 错误或busybox 问题。 Since this is a decade-old software stack, you don't have the recently-introduced date formatting printf builtin bash added in 4.3.由于这是一个已有十年历史的软件堆栈,因此您没有在 4.3 中添加的最近引入的日期格式printf内置 bash。

The easiest workaround is to not use the busybox date command at all, and instead to switch to a scripting language -- Python, Perl, etc. @jhnc was kind enough to provide a perl command for the purpose:最简单的解决方法是根本不使用busybox date 命令,而是切换到脚本语言——Python、Perl 等。 @jhnc非常友好地提供了一个 ZF83A0AA1F9CA0F7DD5994E445 的命令:

perl -e '$|=1; print scalar localtime, "\n"' > file.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 定向到文件时如何刷新Node.js中stdout的管道输出 - How to flush piped output from stdout in Nodejs when directed to file Linux stdout stderr重定向到文件:与终端输出不同 - Linux stdout stderr redirect to file: different from terminal output 从进程中读取标准输出(嵌入式Linux) - Read stdout from a process (linux embedded) linux将数据从文件描述符传送到fifo - linux pipe data from file descriptor into a fifo 从cron运行时,Perl脚本不会将STDOUT输出到文件 - Perl script does not output STDOUT to file when run from cron 在Linux上将stdout重定向到文件时,C ++程序无法产生输出 - C++ program fails to produce output when redirecting stdout to a file on Linux 用于Linux的Delphi Tokyo:将文件内容流传输到stdout(控制台输出) - Delphi Tokyo for Linux : stream file contents to stdout (console output) 将输出从/ dev / video0转储到fifo文件 - dump output from /dev/video0 to fifo file 如果在读/写时出现问题,是否存在 Linux 应用程序,用于通过环形缓冲区使用最后一个数据的 output 到转储文件 - Is exists Linux app for stdin/stdout via a ring buffer with the output of the last data to the dump file if there is a problem when reading/writing Linux FIFO 在我期望的时候没有返回 EOF - Linux FIFO not returning EOF when I expect it to
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM