interact with subprocess

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yaniss
:warning: Old Version Published before Godot 3 was released.

I launch an executable lib with OS.execute. I want to know how to send and read commands to that subprocess. Thanks.

:bust_in_silhouette: Reply From: Artium Nihamkin

It seems that OS.execute has an optional output parameter that can be used to get the output of the command. I have not managed to make it working though. You can see here how this is implemented “under the hood”.

It also appears that there are not support for inter process communications (such as shared memory or pipes) between Godot and other processes in the OS. Even if there was support, I am not sure it would have been portable.

One way to overcome this is to use PacketPeerUDP or StreamPeerTCP to send and receive commands to the other process.
Even though both processes are on the same machine, it is a valid approach. Use localhost as the address to which send the packets.

The thing is to use PacketPeerUDP I need to have sever and client sides. But in my case all I want is to execute a chess engine as executable in another process and then communicate with it. With OS.execute I manage to get only the first output of the engine. I want to keep the connection with the process.

yaniss | 2018-01-06 13:49

How do you normally communicate with the engine?
If you can not modify ithe engine to use UDP/TCP, maybe you can write a wrapper program that would receive packets from Godot and communicate with the chess engine and vice versa.

Artium Nihamkin | 2018-01-06 17:06