I have a framework written in python, and for testing purposes I basically want to do a subprocess (aka shell call) ... that should simply come back with a RC != 0. I tried to invoke some non-existing executable; or to run "exit 1"; but those are for some reason translated to a FileNotFoundError.
So, what else could I do to trigger a return code != 0 (in a "reliable" way; meaning the command should not suddenly return 0 at a future point in time).
I thought to "search" for a binary called exit, but well:
> /usr/bin/env exit
/usr/bin/env: exit: No such file or directory
If you're looking for a system command that always returns a non-zero exit code, then
/bin/false
seems like it should work for you. Fromman false
:You can create a new return code with the command
bash -c "exit RETURNCODE"
, replacing "RETURNCODE" with any number. Note that it will be trimmed to an 8bit unsigned integer (0...255) by (RETURNCODE mod 256)You can check the return code of the last shell command inside the terminal(!) with executing
echo $?
. The "$?" variable contains the most recent return code and "echo" prints it to the standard output.After some more testing, I found that my problem was not on the "Linux" side.
Python has a module shlex; which should be used to "split" command strings. When I changed my subprocess call to use the output of
shlex.split()
invoking "bash exit 1" gives me what I need.