diff --git a/itests/output.feature b/itests/output.feature new file mode 100644 index 0000000000000..2594bb6832abf --- /dev/null +++ b/itests/output.feature @@ -0,0 +1,7 @@ +Feature: output + +Scenario: test for clean output +When command('jbang alias remove dummy-alias-name') +* match exit == 0 +* match out == "" +* match err == "" diff --git a/src/main/scripts/jbang b/src/main/scripts/jbang index 6d628d0440bfa..0525fd48af981 100755 --- a/src/main/scripts/jbang +++ b/src/main/scripts/jbang @@ -152,7 +152,9 @@ output=$(CLICOLOR_FORCE=1 ${JAVA_EXEC} ${JBANG_JAVA_OPTIONS} -classpath ${jarPat err=$? if [ $err -eq 255 ]; then eval "exec $output" -else +elif [ ! -z "$output" ]; then echo "$output" exit $err +else + exit $err fi diff --git a/src/main/scripts/jbang.cmd b/src/main/scripts/jbang.cmd index 3bb58d87be1a1..112682cb708bd 100644 --- a/src/main/scripts/jbang.cmd +++ b/src/main/scripts/jbang.cmd @@ -86,6 +86,7 @@ if "!JAVA_EXEC!"=="" ( if not exist "%TDIR%" ( mkdir "%TDIR%" ) set tmpfile=%TDIR%\%RANDOM%.jbang.tmp rem execute jbang and pipe to temporary random file +set JBANG_USES_POWERSHELL= set "CMD=!JAVA_EXEC!" SETLOCAL DISABLEDELAYEDEXPANSION %CMD% > "%tmpfile%" %JBANG_JAVA_OPTIONS% -classpath "%jarPath%" dev.jbang.Main %* diff --git a/src/main/scripts/jbang.ps1 b/src/main/scripts/jbang.ps1 index 2088f3160cab3..ef4084ec1e962 100644 --- a/src/main/scripts/jbang.ps1 +++ b/src/main/scripts/jbang.ps1 @@ -145,7 +145,9 @@ $global:progresspreference=$old_progresspreference if ($err -eq 255) { Invoke-Expression "& $output" -} else { +} elseif ($output -ne "") { Write-Output $output break +} else { + break }