Question: With python -m pdb -c "c" script.py  the debug mode is entered, when a problem occurs. From the doc, I figured out that the option -c "c" (Python 3.2+) saves me to hit c  + Enter each time at program start. Yet, when the program finishes normally, it outputs The program finished and will be restarted and I still have to hit q + Enter to the quit the program. Is there a way to skip this as well?

Answer: You can add multiple commands for -c in a sequence. METHOD 1: Quitting only if no error is encountered You can just give another command q to jump out of pdb mode incase no error is encountered. If an error is encountered, however, it will enter the debug mode where you will have to continue hitting c and enter to move forward. python -mpdb -c "c" -c "q" script.py  Not encountering an error (quit immediately!)- (base) $ python -mpdb -c "c" -c "q" script.py The program finished and will be restarted (base) $  Encountering an error (enter debug mode!)- (base) $ python -mpdb -c "c" -c "q" script.py Traceback (most recent call last): File "/anaconda3/lib/python3.7/pdb.py", line 1701, in main pdb._runscript(mainpyfile) File "/anaconda3/lib/python3.7/pdb.py", line 1570, in _runscript self.run(statement) File "/anaconda3/lib/python3.7/bdb.py", line 585, in run exec(cmd, globals, locals) File "<string>", line 1, in <module> File "/Projects/Random/script.py", line 6, in <module> """ ModuleNotFoundError: No module named 'thispackagedoesntexist' Uncaught exception. Entering post mortem debugging Running 'cont' or 'step' will restart the program Post mortem debugger finished. The script.py will be restarted > /Projects/Random/script.py(6)<module>() -> """ (Pdb)   METHOD 2: Quitting irrespective of error or not You can use echo "q" and pass it to the next (pdb) command by using the | in the following way. This will run the second command once and immediately take the output of echo "q" to quit - echo "q" | python -mpdb -c "c" script.py  This hits q after the program is done running the script in debug mode. Debug automatically quits after encountering (or not encountering) an error. Not encountering an error (quit immediately!)- (base) $ echo "q" | python -mpdb -c "c" script.py The program finished and will be restarted > /Projects/Random/script.py(6)<module>() -> """ (Pdb) (base) $  Encountering an error (quit immediately!)- (base) $ echo "q" | python -mpdb -c "c" script.py Traceback (most recent call last): File "/anaconda3/lib/python3.7/pdb.py", line 1701, in main pdb._runscript(mainpyfile) File "/anaconda3/lib/python3.7/pdb.py", line 1570, in _runscript self.run(statement) File "/anaconda3/lib/python3.7/bdb.py", line 585, in run exec(cmd, globals, locals) File "<string>", line 1, in <module> File /Projects/Random/script.py", line 6, in <module> """ ModuleNotFoundError: No module named 'thispackagedoesntexist' Uncaught exception. Entering post mortem debugging Running 'cont' or 'step' will restart the program > /Projects/Random/script.py(6)<module>() -> """ (Pdb) Post mortem debugger finished. The script.py will be restarted > /Projects/Random/script.py(6)<module>() -> """ (Pdb) (base) $   Here is the list of commands you can use with pdb - (Pdb) help Documented commands (type help <topic>): ======================================== EOF c d h list q rv undisplay a cl debug help ll quit s unt alias clear disable ignore longlist r source until args commands display interact n restart step up b condition down j next return tbreak w break cont enable jump p retval u whatis bt continue exit l pp run unalias where