0

If I have a script, lets call it "scr.sh" And I call it from another language e.g Python Is there a way to get the traceback of the functions and files back to the Python language.

How I think it could possibly work: the scr.sh

echo "something"
echo `get_traceback` > "/tmp/traceback" 
echo "something else

And a python script "scr2.py"

if __name__ == '__main__'
    self.call_func()

def call_func(self):
    import subprocess
    print "some"
    subprocess.call("scr.sh")
    print "thing"

Can I get the traceback the from the bash script back to the python script? I'd expect that if it exists it would look like this:

file /tmp/scr2.py , line 2 in function "main",
file /tmp/scr2.py , line 7 in function "call_func", 
bash file /tmp/scr.sh, line 2 
Kostadin Krushkov
  • 145
  • 1
  • 3
  • 8
  • does `bash -x scr.sh` help? – glenn jackman Nov 14 '19 at 15:50
  • No, this is going to get the trace of the bash file commands. I don't need that. I ask if it is possible to get the trace back to the originating caller of the script. – Kostadin Krushkov Nov 15 '19 at 06:37
  • 1
    You'd have to generate the python part of the traceback before calling the bash script, and you'll have to make it available to bash (using the environment would be simplest) – glenn jackman Nov 15 '19 at 12:38
  • Yeah, that's what I was hoping to not have to do. The problem is that the bash script could be called from a number of places, and I need to find out from where exactly. Thanks anyway – Kostadin Krushkov Nov 15 '19 at 14:33

0 Answers0