简体   繁体   English

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

[英]redirect stderr stdout both on console and log file

I am using a C API in order to manage my bluetooth thru bluetoothctl. 我正在使用C API以通过bluetoothctl管理我的蓝牙。 It works by using command like : 它可以通过以下命令来工作:

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

All is stored within /tmp/BT_TMP but noting on screen. 全部存储在/ tmp / BT_TMP中,但在屏幕上显示。 I tried by using the following command 我尝试使用以下命令

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

But now all is displayed on screen but file /tmp/BT_TMP is not created. 但是现在所有内容都显示在屏幕上,但是未创建文件/ tmp / BT_TMP。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM