Output from GCODE line

Hi, this is my first post and I want to apologize for my english.

I am looking for a way to have some kind of output from the Pi when a predefined Gcode command appears on the file.
Let me try to explain better, lets use this simple Gcode:

G1 x... y...
G1 x... y... e...

{MyCommand} {parameter}

G1 x... y...
G1 ...

My needs are to power a GPIO pin or preferably a serial write on a second port, not the printer, while the printer is printing. I also need the parameter to be passed, but is only a single digit number.

Any advice? Is that even possible?
Thanks in advance

I believe the plugin OctoPrint GCode System Commands will do what you want.

If the above mentioned plugin doesn't work, you should be able to do what you want by writing your own plugin for OctoPrint. There's hooks you can react to for each gcode command, and from there you could operate your GPIO pins, serial ports etc.