I'm using Python 3.7 and subprocess library.
I have a binary my_prog which crashes with segfault :
$> ./my_prog
[1] 9328 segmentation fault ./my_prog
In my script main.py, I have these lines of code :
try:
output = subprocess.check_output(['./my_prog'], shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
print(exc.returncode)
print(exc.output)
In this case, I get
$> python3 main.py
-11
b''
Ok, subprocess catches the signal SIGSEGV.
Ok, no output. Why not.
But, if I want the same program to read on stdin, I have to modify my line in main.py (the file "text.txt" exists):
output = subprocess.check_output(['./my_prog < text.txt'], shell=True, stderr=subprocess.STDOUT)
And in this case I get :
$> python3 main.py
139
b'/bin/sh: line 1: 17235 Segmentation fault: 11 ./my_prog < text.txt\n'
I know it's 11 + 128, that means SIGSEGV too.
And, now, I have an output !
Even if 139 and -11 mean the same, why the returncode changes in these 2 different situations ? And why is there no output in the first case ?
Thanks :)
EDIT :
Add the difference on output issue.