向标准输出添加时间戳

发布于 2025-01-13 12:29:28 字数 694 浏览 5 评论 0原文

我发现这两个类似的问题: 将 stdout 重定向到文件并添加时间戳如何向 STDERR 重定向添加时间戳 以将 stdout 重定向到文件。

我想在将行写入文件时添加时间戳。目前,我像这样编写日志文件:

START cmd /c %PATH_STLink-OPENOCD%\openocd.exe -f %CD%\%CFG_File% -s %PATH_SUPPORTFILES% -d0 ^> output.txt

如果输出看起来像这样(使用%date%和%time%),那就太好了。希望这是可能的:

[10.03.2022, 16:11:40,45]output of openocd.exe
[10.03.2022, 16:11:42,21]output of openocd.exe
[10.03.2022, 16:11:43,65]output of openocd.exe

非常感谢!

i found these two similar questions: Redirect stdout to a file and add a timestamp and How to add timestamp to STDERR redirection to redirect stdout to a file.

I want to add a timestamp when the line is written to the file. At the moment I wrtie the log file like this:

START cmd /c %PATH_STLink-OPENOCD%\openocd.exe -f %CD%\%CFG_File% -s %PATH_SUPPORTFILES% -d0 ^> output.txt

It would be nice, when the output could look like this (using %date% and %time%). Hopefully this is possible:

[10.03.2022, 16:11:40,45]output of openocd.exe
[10.03.2022, 16:11:42,21]output of openocd.exe
[10.03.2022, 16:11:43,65]output of openocd.exe

Thank you very much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2025-01-20 12:29:28
<NUL >output.txt set /p=[%date%, %time%]
start ... >>output.txt

应该将 set/p 的提示放入新文件 output.txt 中,不带换行符;然后附加你想要的数据。

<NUL >output.txt set /p=[%date%, %time%]
start ... >>output.txt

should put the prompt for the set/p into the new file output.txt with no newline; then append the data you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文