# Execute a certain code after simulation finish

**URL:** <https://community.gatling.io/t/execute-a-certain-code-after-simulation-finish/9354>\
**Category:** Gatling (Open-Source)\
**Created:** [October 15, 2024, 9:33am UTC](https://community.gatling.io/t/execute-a-certain-code-after-simulation-finish/9354 "2024-10-15T09:33:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trinp](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/trinp/32/1593_2.png) [@trinp](https://community.gatling.io/u/trinp)\
**Post date:** [October 15, 2024, 9:33am UTC](https://community.gatling.io/t/execute-a-certain-code-after-simulation-finish/9354/1 "2024-10-15T09:33:16Z")

</div>

**Gatling version** : 3.12.0 (must be up to date)

Hello, I have a little function that I want to execute on generated simulation.log and stats.json after I finish the simulation, on Gatling there are `hooks` but the hooks are before the log generated, as stated in doc:

```auto
Gatling starts
Simulation constructor is called, and all the code in the class body that is not delayed in the before and after hooks is executed.
before hook is executed
Simulation runs
Simulation terminates
-> after hook is executed //cannot be used due to HTML and json raw reports are generated in next step
-> HTML reports are generated if enabled
-> My desired code block in this step
Gatling shuts down

```

I have tried passing my method after `setUp` as below, but the result will be shown in the beginning of the run, which is false:

```auto
...
...
setUp(DemoSimulation)
myMethod() //it fails here

```

Or weirder is to run `scalac` and build another `main` program just to execute my need, but that would be too absurd and time wasted.  
Is there any flag or approach that I could use for this kind of problem ?

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [October 15, 2024, 7:02pm UTC](https://community.gatling.io/t/execute-a-certain-code-after-simulation-finish/9354/2 "2024-10-15T19:02:27Z")

</div>

This is not a supported usage.  
Moreover, as the editor, we can’t help with building your own DIY platform.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [October 15, 2024, 7:02pm UTC](https://community.gatling.io/t/execute-a-certain-code-after-simulation-finish/9354/3 "2024-10-15T19:02:32Z")

</div>

Closed on October 15, 2024, 7:02pm UTC


