How to avoid electricity to pass through inverter output socket but output socket will always be connected to electric line?
What can I do to ensure that the inverter output port will always be connected with electric line, but the electricity will flow towards one direction only, from the inverter to electric line?

There is nothing you can do if the  inverter is not a grid-tie type.

Your mains is AC which means current is alternating. You can't block current in one direction.
A grid-tie inverter will track the mains frequency, voltage and phase and adjust the output to match. Your inverter probably doesn't have this feature so you can't  connect it to the mains.

There will be local regulations covering addition of inverters to the mains. You have to have permission to do this so that you don't kill someone working on the line when the power is supposed to be off.