Close only stdin pipe when using OS.execute_with_pipe

Godot Version

v4.5.1.stable.official [f62fdbde1]

Question

When using OS.execute_with_pipe to execute a program with pipes, is it possible to only close the stdin pipe while leaving the stdout pipe open?

I have a program that reads from stdin until EOF, and then outputs to stdout after it is finished processing the data from stdin. Whenever I execute it with OS.execute_with_pipe and get the pipe FileAccess from the stdio key in the dictionary, I can try to read and write from it but:

  • If I write all of my data to the pipe FileAccess but don’t call close() on it, I will be blocked reading forever because the program I am executing only advances after getting EOF from stdin.
  • If I write all of my data to the pipe FileAccess and call close() on it, the program I am executing will advance since stdin is closed and giving EOF, but will crash when trying to write to stdout since that pipe closes too.

So is there a way to close only the stdin pipe, or at least somehow have the program I am executing receive EOF so it continues and writes to stdout?

Are you sure the second pipe is closed too, and it doesn’t crash for whatever other reason? There are two separate pipes with two separate handles, and two separate FileAccess objects, I’d expect them to work independedly from one another.

Anyway, you could send the data size first, or choose some byte signature to mark the data end, instead of relying on EOF.

1 Like

Is there a way to get the stdin and stdout pipes separately? I thought they were bundled together as one FileAccess object from OS.execute_with_pipe, and that the only other pipe included as a separate FileAccess object was stderr.

This is the solution I ended up taking, by adding a byte limit argument/flag to my program.

Still wondering if you can actually close in stdin/stdout pipes separately though, because if not, it would be nice functionality to add in the future.

1 Like

Ah you are right. It does pack both io pipes into the first FileAccess, I have read that wrong.