Opamp driving 24V signal through long wire
Most op-amps will effectively drive a capacitive load providing there's a series output resistor used. Given also that your application doesn't involve negative feedback (you are operating as a comparator) there should be realistically no problems of instability leading to oscillations to worry about.

Depending on the op-amp and the type of load at the end of the cable and what sort of attenuation you can tolerate, I'd use a 220 ohm resistor in series with the op-amp output. It would help if the op-amp is known though.


  It's a 24V digital input of a controller so I'd assume there's not
  much load. I just have no experience with these kind of signal
  transmition


OK a couple of things you need to be aware of here: -


if the op-amp power supply is 24 volts then the maximum op-amp output (without a more specialist choice) will be about 22 volts for a regular non-rail-to-rail device
Assuming above, the minimum output might only be 2 volts above ground
You need to decide whether this is acceptable and if not either choose slightly different power rails for the op-amp or choose a rail-to-rail device
I'd also be tempted to put a unidirectional TVS diode across the output that feeds the cable (output to local 0 volts)
You also want to avoid ground loops so if your op-amp power supply is grounded and the digital controller 0 volts is also grounded, you might need to take precautions to avoid ground loops circulating any ground fault currents from machines locally through the interconnecting cable. This might mean opto-isolating the op-amp output.