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


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?
Yes, there is. Put your commands that you want to execute before executing your application in a custom script (e.g. 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.
One more thing: you could add the detection whether the script is being debugged to See StackOverflow for some ideas how to do this.

Please sign in to leave a comment.