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

redirect stderr stdout both on console and log file

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

./BT_API connect  | bluetoothctl > /tmp/BT_TMP

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

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

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

使用 tee,这会将标准输入重定向到文件和标准输出:

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