Skip to content

SDL_Process stdin errors with SDL_FlushIO #13116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Semphriss opened this issue May 24, 2025 · 0 comments
Open

SDL_Process stdin errors with SDL_FlushIO #13116

Semphriss opened this issue May 24, 2025 · 0 comments
Milestone

Comments

@Semphriss
Copy link
Contributor

I'm opening this issue because I'm not sure if there's a particular reason to work that way, but I noticed I can't flush a process input pipe.

#include <SDL3/SDL.h>

int main(void)
{
  const char *args[] = { "cat", NULL };
  char buf[16] = { '\0' };

  SDL_Init(0);

  SDL_Process *proc = SDL_CreateProcess(args, true);
  SDL_IOStream *in = SDL_GetProcessInput(proc);
  SDL_IOStream *out = SDL_GetProcessOutput(proc);

  SDL_WriteIO(in, "ab", 2);
  bool success = SDL_FlushIO(in);  // <-- Here
  SDL_Log("Success: %d\n", success);
  SDL_Log("%s\n", SDL_GetError());

  SDL_Delay(10); // Give the child process some time to pass its stdin to stdout

  SDL_ReadIO(out, buf, sizeof(buf));
  SDL_Log("'%s'\n", buf);

  SDL_KillProcess(proc, false);
  SDL_WaitProcess(proc, true, NULL);
  SDL_DestroyProcess(proc);

  SDL_Quit();
  return 0;
}

Output:

Success: 0
Error flushing datastream: Invalid argument
'ab'

Writing to the child process' input seems to automatically flush, so the call to SDL_FlushIO doesn't seem to be necessary. However, would it be better to make that function a successful no-op instead?

@slouken slouken added this to the 3.4.0 milestone May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants