Questions tagged [exit-code]

34 questions
421
votes
11 answers

Can I make cURL fail with an exitCode different than 0 if the HTTP status code is not 200?

I was always assuming that when curl got an HTTP 500 response it was returning an exit code that meant failure (!= 0), but that seems to be not the case. Is there a way I can I make cURL fail with an exitCode different than 0 if the HTTP status code…
knocte
  • 4,476
  • 2
  • 14
  • 18
141
votes
12 answers

Getting ROBOCOPY to return a "proper" exit code?

Is it possible to ask ROBOCOPY to exit with an exit code that indicates success or failure? I am using ROBOCOPY as part of my TeamCity build configurations, and having to add a step to just silence the exit code from ROBOCOPY seems silly to…
Lasse V. Karlsen
  • 3,510
  • 9
  • 38
  • 58
48
votes
2 answers

Can I make SSH fail when a port forwarding fails?

If I do a remote port forward, a la -R 3690:localhost:3690 when a binding already exists on the port on the remote host, I get this warning: Warning: remote port forwarding failed for listen port 3690 Is there a way to have ssh fail (i.e. exit with…
Matt Joiner
  • 995
  • 2
  • 11
  • 27
19
votes
2 answers

How to make TaskScheduler fail when the task returns result different from 0

I have a backup task that fails with a non zero result, yet Task Scheduler says that it executed the task correctly. Is there any way to tell Task Scheduler that the task failed?
Pablo Montilla
  • 435
  • 1
  • 4
  • 14
10
votes
1 answer

How to exit with an error code from nano?

When using vim for “replying” to some program – typically git – it can be useful to deliberate exit with error, to abort the entire action that opened the window. Like $ git commit -a # vim opens, showing me the staged files and asking for a commit…
leftaroundabout
  • 424
  • 3
  • 15
9
votes
3 answers

How do you use PIPESTATUS, tee and /bin/sh together?

When I run curl | tee test.txt; echo ${PIPESTATUS[0]} I correctly see curl: try 'curl --help' or 'curl --manual' for more information 2 But when I try to run exactly same command using '/bin/sh': sh -c "curl | tee test.txt; echo…
Yasser Zamani
  • 2,537
  • 2
  • 14
  • 15
9
votes
4 answers

Accessing an exit code outside of a su -m $USER -c ""

The below command prints "0" or "1" correctly depending on failure or not because i put $? inside the "su" command. sudo su -m $USER -c "./shutdown.sh &> /dev/null; echo \$?" However, if i do this: sudo su -m $USER -c "$BASE/bin/shutdown.sh &>…
Nick
  • 495
  • 1
  • 4
  • 10
6
votes
1 answer

Use output of command as exit code

For my Continuous Integration scripts I want to check if the git branch is not in sync with the master branch. Therefore I use git rev-list --left-right --count master...my-branch-name It will return sth. like 1 3 (3 commits ahead of master, 1…
Sven R.
  • 165
  • 5
5
votes
2 answers

In a bash script, how do I check if "-e" is set?

I use set -e in scripts quite often, but sometimes, it's ok for a script to fail in some of it's commands. I tried checking if set -e was ON, but couldn't find a way to do it - there's no option (that I know of) in set that will provide the current…
4
votes
2 answers

exit code 128, what's the reason?

As per definition exit code 128 means 'invalid exit argument'. But i always get 255 (Exit status out of range) in case argument is invalid like float number. Is this the proprietary implementation on my linux distribution? # exit 1.234 exit bash:…
P K
  • 2,153
  • 11
  • 28
  • 31
3
votes
2 answers

What's the exit code for "curl -I" when not HTTP 200?

I want to check what HTTP status code is returned for an HTTP(S) URL. I don't care about content, so I just request head with curl -I $url or curl --head $url But what's the exit code I should check for, e.g. in subprocess.check_call? In…
Nemo
  • 1,114
  • 1
  • 12
  • 29
3
votes
1 answer

How do I invert the exit code of a program or pipe within ZSH?

I want to invert the exit code of a piped command sequence: foo | bar within the ZSH. So 0 maps to 1 and 1-128 maps to 0.
math
  • 2,507
  • 7
  • 27
  • 43
2
votes
3 answers

Exit code 127 in cygwin64

After years without problems, suddenly several programs in my installation of cygwin64 on 64-bit Windows 7 Professional are failing to run, and instead appear to exit immediately with code 127, which usually means "command not found" in Bash. In…
Tim Parenti
  • 145
  • 2
  • 11
2
votes
1 answer

CMD prompt: %ERRORLEVEL% gets the correct output value from the second run

I have wolframscript installed on my Windows 10 PC. Running the following commands on the command prompt get me > where /q wolframscript & echo %ERRORLEVEL% 9009 <<< why didn't I get 0? > where /q wolframscriptss & echo %ERRORLEVEL% 0 <<<…
Diaa
  • 177
  • 6
2
votes
2 answers

Why does `%errorlevel%` expand to empty string in DOSBox?

Trying to automate some DOSBox scripting for an old program, I wanted to use the exit code usually in errorlevel to control the program flow. The input is given in a hello_db.bat file: @echo off set msg=Hello echo %msg% dir echo errorlevel =…
Morten Zilmer
  • 530
  • 1
  • 3
  • 13
1
2 3