Function proposal: SDL_Execute

Message-ID:
<CAFbsDtintCP1QJyVaEMWGNTJ5EGE0uMu9cdYjj_6sPUO8OYnqw at mail.gmail.com>
Content-Type: text/plain; charset=“utf-8”

That could be useful.

I’d much rather have an exec(3) -style function, something like SDL_ExecVP()
and/or SDL_ExecVP(). (With system() -like semantics when it comes to actual
process management.) Escaping arguments for a system() call is somewhat
terrifying, as someone would probably inevitably try to do so anyway.

A flag to have it go into the background and forget about it might be
useful,
but then again you could very well in such a case just call it from another
thread.

A flag to have it REPLACE the current thread/process would probably be
worthwhile as well, since the caller might just be some sort of loader
(or might be making the call to run an updater program: on Windows you
can’t overwrite an executable that’s running, so actual program
updates require this sort of dance).> Date: Tue, 11 Nov 2014 21:35:50 +0200

From: Melker Narikka
To: SDL Development List
Subject: Re: [SDL] Function proposal: SDL_Execute

Date: Tue, 11 Nov 2014 17:20:29 -0300
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Subject: Re: [SDL] Function proposal: SDL_Execute
Message-ID:
<CAEyBR+W_HQn5uL=FD3mDHuf6mJ7tRDFt7YJ8pyfCxBGDaNznCw at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2014-11-11 16:35 GMT-03:00, Melker Narikka :

I’d much rather have an exec(3) -style function, something like
SDL_ExecVP()
and/or SDL_ExecVP(). (With system() -like semantics when it comes to actual
process management.) Escaping arguments for a system() call is somewhat
terrifying, as someone would probably inevitably try to do so anyway.

Ugh right, and in fact that’s the very thing I’m doing x_x OK, adapt
it for that then. The important thing is that the functionality is
there.

A different name than Exec might be wise as well, since every Exec
function that I’ve ever heard of REPLACES the current program.

Date: Tue, 11 Nov 2014 19:46:14 -0800
From: Andreas Schiffler
To: SDL Development List
Subject: Re: [SDL] Function proposal: SDL_Execute
Message-ID: <5462D806.8010906 at ferzkopp.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

There was work done on something like this for the GSoC visualtest
project, since the visual test harness needed to launch an SDL
application as independent process (i.e. to be able to capture
screenshots of a windowed SDL app).

An actual implementation of this was just done for Windows (source is
here: SDL/visualtest/src/windows) since the project ran out of time
while extending it to Unix, but the API had a well thought-out interface
which includes some important functionality (checking if a process is
running, killing a process) and encapsulating platform specific details
in structs.

I’d suggest to consider something like this:
int SDL_LaunchProcess(char* file, char* args, SDL_ProcessInfo* pinfo)
int SDL_GetProcessExitStatus(SDL_ProcessInfo* pinfo,
SDL_ProcessExitStatus* ps)
int SDL_IsProcessRunning(SDL_ProcessInfo* pinfo)
int SDL_QuitProcess(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps)
int SDL_KillProcess(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps)

This ALMOST sounds like a SDL pipes implementation that I did. I
haven’t touched it in a while (never had anything ready for it, so
never tried to compile it either), but I’ll attach the code that I
have convenient.

Date: Wed, 12 Nov 2014 01:21:30 -0300
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Subject: Re: [SDL] Function proposal: SDL_Execute
Message-ID:
<CAEyBR+W_CVrJks2MuDkEWyxeEep=qw7ZSB7Ut5f5J7qmoEnv5w at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2014-11-12 0:46 GMT-03:00, Andreas Schiffler :

int SDL_LaunchProcess(char* file, char* args, SDL_ProcessInfo* pinfo)

I’m not sure you’d want to pass args as a single string, due to what
was mentioned earlier about escaping.

So:
int SDL_LaunchProcess
(
char *file,
int argn, char **args,
SDL_ProcessInfo *pinfo
);

Or:
int SDL_LaunchProcess
(
char *file,
char **args,
SDL_ProcessInfo *pinfo
);
With the requirement that a null pointer be the last entry in the argument list?

I personally prefer the variant with the length argument, since I
think it’s less likely to get misunderstood.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdlpipe_windows.c
Type: text/x-csrc
Size: 13625 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20141113/9c6bdd7d/attachment.c