Script via STDIN does not exit with error code and does not stop correctly
See original GitHub issueSteps to reproduce
Link to a related Problem in GitLab: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27830#note_564599211
Test.ps1:
$ErrorActionPreference = 'Stop'
just bogus
Write-Host 'hello'
Batch-Call (working correctly with file)
pwsh -File Test.ps1
Exit-Code: 1
Batch-Call (working correctly with stdin)
type Test.ps1 | pwsh -noprofile -noninteractive -command "$input | iex"
Exit-Code: 1
Batch-Call (not working correctly with stdin)
type Test.ps1 | pwsh -Command -
Exit-Code: 0
Expected behavior
Powershell quits with non zero exit code and does not print "hello", but an exception for "just bogus"
Actual behavior
Powershell does execute all statement even though $ErrorActionPreference is set to "stop"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:28 (11 by maintainers)
Top Results From Across the Web
Why does the script command not return the correct exit ...
Simply put: $ script -V script from util-linux 2.23.2 $ cat /etc/centos-release CentOS Linux release 7.9.2009 (Core) $ false && echo This is...
Read more >Make bash script exit if no user input in stdin
The issue is that if you just press enter the script executes as though a "y" or a "Y" have been input, and...
Read more >set -e subshell doesn't exit on the first command that fails if ...
I have a script.sh and I have to correctly diagnose any errors inside it, so the prova function in case of an error...
Read more >How do I close stdin in a shell script? - bash
I have a misbehaving program that I need to call from my script. It exits as soon as it sees something on stdin....
Read more >Thread: psql dones't reflect exit status if input command via stdin
Hello, I found when running command like `# echo "xxx" | psql postgres postgres`, the return code is always 0 even though the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found out, that with 2 linebreaks behind the command it is working:
Just 2 empty lines behind the closing bracket and it is working.
The other working one is:
I wouldn’t say it’s completely unusable there are workarounds that make this entirely possible. The method I usually use is this