When I run BashOperator, why I can not see the standard output from a C++ program on tasks’ log page on web UI

  airflow, airflow-webserver, c++

We are using airflow to run a C++ program through BashOperator. We want to see the standard output and standard error given by this C++ program from aiflow’s Log page. But the logs are not shown up.
A very simple C++ code to test:

#include <iostream>
int main()
{
    while(true)
    {
        std::cout << "Testn";
        sleep(1);
    }
}

BashOperator:

bash_task=BashOperator(
    task_id="demo_bash_task",
    dag=dag,
    bash_command='/tmp/cpptest'
)

However, if I run the bash script below through BashOperator, I can see the logs will be continuouly printed on the Log page in Airflow

#!/bin/bash
while :
do
    echo "Test"
    sleep 1
done

enter image description here

My question is, why there are different behavior between C++ and bash programs to airflow. To me they both do the standard output. How can I make C++ program work.

Source: Windows Questions C++

LEAVE A COMMENT