Debug Configurations - is it possible to run a few lines of code or a script file prior to debug session start?

Hi,

I have some commands Im running eveny time a script is being debug. this are mainly viewing commands to allow better console printing. I so that i can run an external tool before debug starting using Debug configurations, but i didnt see no script running possibility. I dont want to make my scripts dirty by inserting at each one the commands needed.

Any solution?
0
2 comments
Yes, there is. Put your commands that you want to execute before executing your application in a custom script (e.g. before_debug.py and define it as an external tool).

Then, go to your run configuration (click on the dropdown in the toolbar, choose Edit configurations...) and at the bottom of the dialog there's the actions that are performed before launching an application.

Clicking on plus, you'll be able to add "Run external tool" to the list of operations that should be executed before your application. There's no way to directly insert a bunch of commands, but this should be a viable workaround.

Please note, that this only affects the current run configuration. But in the tree on the right, you can expand the node "Defaults" and make the same settings for a particular type of run configurations (e.g. all Python applications or unit tests). There's no way however, to distinguish between executing as run or debug configuration.
0
One more thing: you could add the detection whether the script is being debugged to before_debug.py. See StackOverflow for some ideas how to do this.
0

Please sign in to leave a comment.