# Gcode\_shell\_command timing

**URL:** <https://klipper.discourse.group/t/gcode-shell-command-timing/6056>\
**Category:** General Discussion\
**Created:** [January 19, 2023, 11:00pm UTC](https://klipper.discourse.group/t/gcode-shell-command-timing/6056 "2023-01-19T23:00:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcus-in-3d](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marcus-in-3d](https://klipper.discourse.group/u/marcus-in-3d)\
**Post date:** [January 19, 2023, 11:00pm UTC](https://klipper.discourse.group/t/gcode-shell-command-timing/6056/1 "2023-01-19T23:00:34Z")

</div>

I’m currently using `gcode_shell_command` and `RUN_SHELL_COMMAND` to execute a shell command from the gcode. However, this shell command is executed way, way before commands that come before it in the gcode file are processed by the mcu. It seems like the shell command is executed after the preceding gcode is sent to the mcu’s input queue, rather than when that gcode is (expected to be) actually processed on the mcu.

Is there some way to synchronize these somehow?

Or perhaps approximated within a second or so?

---

<div class="post-metadata">

**Author:** ![marcus-in-3d](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marcus-in-3d](https://klipper.discourse.group/u/marcus-in-3d)\
**Post date:** [January 19, 2023, 11:52pm UTC](https://klipper.discourse.group/t/gcode-shell-command-timing/6056/2 "2023-01-19T23:52:19Z")

</div>

I also noticed that Klipper supports `M400` which waits for current moves to finish. Could that perhaps be used to empty the mcu’s queue, or in some other way synchronize the `RUN_SHELL_COMMAND` execution? (I wouldn’t mind if the printer would just stop for a second while the command is executed.)
