Questions tagged [exit-code]

36 questions
607
votes
13 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
  • 6,381
152
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…
58
votes
3 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
  • 1,102
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?
18
votes
2 answers

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…
10
votes
4 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…
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
  • 535
7
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…
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
votes
1 answer

Exit status of commands before last command

On OS X, Linux, and other systems, you can use $? to get the exit code of the last command. Is there any way to exit codes of older commands? Either by saying "give me the exit code of the nth previous command" or by saying "give me the exit code…
4
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,693
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,233
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,151
2
votes
1 answer

How to check return status of command invoked from command line in windows?

reg import RegFile.reg How to check return code of this command ?
Ashish
  • 187
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…
1
2 3