在控制台和日志文件上重定向stderr stdout
问题描述:
我正在使用C API来管理蓝牙通过bluetoothctl。它通过使用如下命令起作用:在控制台和日志文件上重定向stderr stdout
./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
,将标准输入重定向到两个文件和stdout:
./BT_API connect $2 | bluetoothctl 2>&1 | tee /tmp/BT_TMP