diff --git a/script/tools/ck-docker b/script/tools/ck-docker index 6c118561b7..19e539909f 100755 --- a/script/tools/ck-docker +++ b/script/tools/ck-docker @@ -112,6 +112,19 @@ cmd_exec() { local docker_flags=() [ -t 0 ] && [ -t 1 ] && docker_flags+=("-it") + # Auto-detect Python commands and enable unbuffered output for live streaming + local is_python=false + for arg in "$@"; do + if [[ "$arg" == "python" || "$arg" == "python3" || "$arg" == *.py ]]; then + is_python=true + break + fi + done + + if [ "$is_python" = true ]; then + docker_flags+=("-e" "PYTHONUNBUFFERED=1") + fi + docker exec "${docker_flags[@]}" "${CONTAINER_NAME}" "$@" } diff --git a/script/tools/ck-exec b/script/tools/ck-exec index dfc7655774..5d5dd2bded 100755 --- a/script/tools/ck-exec +++ b/script/tools/ck-exec @@ -103,9 +103,18 @@ for arg in "${command_args[@]}"; do cmd_string="${cmd_string} $(printf '%q' "$arg")" done +# Auto-detect Python commands and enable unbuffered output for live streaming +env_flags="" +for arg in "${command_args[@]}"; do + if [[ "$arg" == "python" || "$arg" == "python3" || "$arg" == *.py ]]; then + env_flags="-e PYTHONUNBUFFERED=1" + break + fi +done + # Execute command if [ "$interactive" = true ]; then - docker exec -it -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" + docker exec -it ${env_flags} -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" else - docker exec -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" + docker exec ${env_flags} -w "${workdir}" "${CONTAINER_NAME}" bash -c "${cmd_string}" fi