Skip to content

Commit

Permalink
fix(bash): improve bash last line as result reliability using bash pr…
Browse files Browse the repository at this point in the history
…ocess substitution (#5321)
  • Loading branch information
rubenfiszel authored Feb 18, 2025
1 parent 07237a0 commit 138cedf
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions backend/windmill-worker/src/bash_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,17 @@ cleanup() {{
trap '' SIGTERM SIGINT
# Kill the process group of the script (negative PID value)
pkill -P $$
pkill -P $$ 2>/dev/null || true
exit
}}
# Trap SIGTERM (or other signals) and call cleanup function
trap cleanup SIGTERM SIGINT
# Create a named pipe
mkfifo bp
# Start background processes
cat bp | tail -1 >> ./result2.out &
# Run main.sh in the same process group
{bash} ./main.sh "$@" 2>&1 | tee bp &
{bash} ./main.sh "$@" 2>&1 | tee >(tail -1 >> ./result2.out) &
pid=$!
Expand All @@ -121,7 +116,6 @@ wait $pid
exit_status=$?
# Clean up the named pipe and background processes
rm -f bp
pkill -P $$ || true
# Exit with the captured status
Expand Down Expand Up @@ -624,7 +618,7 @@ $env:PSModulePath = \"{};$PSModulePathBackup\"",
write_file(
job_dir,
"wrapper.sh",
&format!("set -o pipefail\nset -e\nmkfifo bp\ncat bp | tail -1 > ./result2.out &\n{} -F ./main.ps1 \"$@\" 2>&1 | tee bp\nwait $!", POWERSHELL_PATH.as_str()),
&format!("set -o pipefail\nset -e\n{} -F ./main.ps1 \"$@\" 2>&1 | tee >(tail -1 >> ./result2.out) &\nwait $!", POWERSHELL_PATH.as_str()),
)?;

#[cfg(windows)]
Expand Down

0 comments on commit 138cedf

Please sign in to comment.