I am writing a Python Script handling the exit codes of different shell scripts.
When i call the shell script via command prompt and ask for the exit code with echo $?, I get a 1.
When I call the shell script via the python script, I assume the value will be 1, but instead it turns out to be 256.
What happened?
This is my shell Script for testing a Camera:
#!/bin/bash
#cam.sh
if [ -r /dev/video0 ]
then
#taking a picture
ffmpeg -f video4linux2 -s 640x480 -i /dev/dev0 -ss 0:0:2 -frames 1 ~/Desktop/testbild.jpg 2>/dev/null
#showing a stream
timeout 10s vlc v4l2:///dev/video0 --no-audio --no-video-title-show
exit 0
else
exit 1
fi
And my Python call:
#!/usr/bin/env python
#exitcodetest.py
import os
command = "sh ~/Desktop/cam.sh"
camera = os.system(command)
print(camera)
Why?