core/cmd: fix for stacking mixed output redirects. (#5000)

That is redirect to file + redirect to buffer which happens when calling rz_core_cmd_str .
This commit is contained in:
karliss 2025-03-14 16:59:06 +02:00 committed by GitHub
parent d3f7ef2aa9
commit 55a4f9e54c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -3404,6 +3404,8 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_stmt) {
} else {
rz_cons_flush();
RZ_LOG_DEBUG("redirect_stmt: fdn = %d, is_append = %d\n", fdn, is_append);
rz_cons_push();
rz_cons_set_flush(true);
RzConsPipe *cpipe = rz_cons_pipe_open(arg_str, fdn, is_append);
if (cpipe) {
if (!pipecolor) {
@ -3416,6 +3418,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_stmt) {
} else {
RZ_LOG_WARN("Could not open pipe to %d\n", fdn);
}
rz_cons_pop();
}
free(arg_str);
fail:

View file

@ -37,3 +37,25 @@ Hello
World
EOF
RUN
NAME=stacked redirect
FILE==
CMDS=<<EOF
# inner redirect to file
(mac1; echo a>.rz-stacked-redirect.txt; echo b)
# outer redirect to alias, any other feature which redirects output to buffer like the builtin grep ~ would also work
.(mac1) > $al1
echo "---"
cat .rz-stacked-redirect.txt
echo "---"
$**
rm .rz-stacked-redirect.txt
EOF
EXPECT=<<EOF
---
a
---
$al1=$b
EOF
RUN