Search code examples
python-2.7pwntools

how to continue in a python script, if the program exits/crashes with pwntools?


I want to continue the python script do things, when the program crashes/exits. But it does not work. For example:

from pwn import *

p = process("./proc")

p.interactive()
<do stuff and exit>

print("Some stuff")

But when the progam proc exits/crashes, the part below p.interactive() is not executed. Can someone help?


Solution

  • you should use a "try except" which allows you to run code in the try part, and once the program crashes it moves on to the except. read more here.

    an example:

    try:
      print(x)
    except NameError:
      print("Variable x is not defined")
    except:
      print("Something else went wrong")