linux - 在控制台和日志文件上重定向 stderr stdout

标签 linux bash stdout stderr

我正在使用 C API 来通过 bluetoothctl 管理我的蓝牙。它通过使用如下命令工作:

./BT_API connect $2 | bluetoothctl > /tmp/BT_TMP

所有内容都存储在/tmp/BT_TMP 中,但会在屏幕上注明。我尝试使用以下命令

./BT_API connect $2 | bluetoothctl 2>&1 /tmp/BT_TMP

但现在所有内容都显示在屏幕上,但文件/tmp/BT_TMP 尚未创建。

最佳答案

使用 tee,它将 stdin 重定向到文件和 stdout:

./BT_API connect $2 | bluetoothctl 2>&1 | tee /tmp/BT_TMP

关于linux - 在控制台和日志文件上重定向 stderr stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28671962/

相关文章:

c - 为什么 stdout 在重定向到文件时需要显式刷新?

linux - 为什么信号量被视为IPC?

c - 无法从标准输出读取

c - 将 printf 重定向到串行端口

linux - 将目录下所有文件的第5列除以3?

linux - 无法安装 rJava

bash - 使用 While 和 grep 组合 - "syntax error near unexpected token ` <' "

linux - 使用文件计数列出文件夹的 UNIX 命令

regex - 从 bash 脚本中寻找一个句子

node.js - 错误 : write EPIPE when piping node output to "| head"