[英]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
看起来有一些很好的信息,但我不会假装知道如何解释它:
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.