Você pode usar o módulo subprocesso em Python 3 ou o módulo commands para o Python 2 da seguinte forma:
status, result = subprocess.getstatusoutput("ls -al")
status, result = commands.getstatusoutput("ls -al")
Em seguida, teste o valor de status .
Exemplos do site:
>>> import subprocess
>>> subprocess.getstatusoutput('ls /bin/ls')
(0, '/bin/ls')
>>> subprocess.getstatusoutput('cat /bin/junk')
(256, 'cat: /bin/junk: No such file or directory')
>>> subprocess.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found')