在脚本执行完成之前 tee 不会写入文件?

tee won't write to file until script finishes executing?

我正在尝试从 Android 应用自动收集性能数据(加载和屏幕渲染时间)。在使用 adb 命令获取性能数据之前,我使用 test-runner.py(内部工具)构建应用程序并使用 运行 测试。我的 bash 脚本如下所示:

BASE_DIR=../Application/app/src/custom-feeds
CTF_DIR=../../../../ComponentTestFramework
OUTPUT_FILE=out.txt

if test -e $OUTPUT_FILE
then
    rm $OUTPUT_FILE
fi

teardown ()
{
    cd $BASE_DIR
    adb logcat -d PerformanceTest:D *:S | grep 'Loading' | tee -a $OUTPUT_FILE
    adb logcat -d ActivityManager:I *:S | grep 'ContentBrowseActivity:\s+\+' | tee -a $OUTPUT_FILE
    ./restore.sh
}

# small sample feed

echo Testing sample feed with 10 initial items
echo size = 10 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-10.json
teardown

# medium sample feed

echo Testing sample feed with 100 initial items
echo size = 100 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-100.json
teardown

# large sample feed

echo Testing sample feed with 500 initial items
echo size = 500 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-500.json
teardown

# super large sample feed

echo Testing sample feed with 5000 initial items
echo size = 5000 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-5000.json
teardown

当脚本首先 运行 时,数据按预期写入输出文件:

size = 100

但是,在脚本完成执行之前,不会写入任何其他内容。输出文件现在看起来像这样:

size = 5000
D/PerformanceTest( 1458): Loading time: 332874 ms
I/ActivityManager( 1843): Displayed com.amazon.android.calypso/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +563ms

有两个问题:

  1. 原始数据("size = 100")已写入。这不应该发生,因为 tee 中的 -a 开关。
  2. 中间结果没有写入文件,即使我在脚本外执行该命令时该命令有效。

我做错了什么?

尴尬地回答我自己的问题。

问题是由于我使用 >(覆盖文件)而不是 >>(附加到文件)。使用 >> 显然解决了问题。我打字的时候还在捂脸。