How to control a running slicer from the command line

I know how to use the python console to control slicer.

But now I want to control the python console through an external program,
My idea is to control the python console by entering commands through cmd, and then control the slicer scene.

How to achieve it?

For example, I want to print “HelloWorld” in the current python console through the cmd command.

You can use the WebServer module for this:

https://slicer.readthedocs.io/en/latest/user_guide/modules/webserver.html#remote-control