我正在使用 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/