#include <xtend/proc.h>
-lxtend
char *parse_cmd(char *argv[], const char *cmd)
argv: Pointer array to be filled with command tokens
cmd: Raw command string with limited meta-character support
from strshellcpy(3)
Breaks a shell command into an argv[] style array suitable for spawnvp() or
execv*(). A copy of cmd is created using strshellcpy(), which expands certain
shell features such as variables and paths starting with '~'. The copy is then
modified by replacing separators with '0' and the argv[] array is populated
with pointers to each token in the copy.
Pointer to strdup() copy of cmd, which should be freed as soon as possible when
argv[] is no longer needed.
char *cmd, *argv[], *expanded_cmd;
expanded_cmd = parse_cmd(argv, cmd);
spawnvp(P_WAIT, P_NOECHO, argv, NULL, NULL, NULL);
free(expanded_cmd);
spawnvp(3), spawnlp(3), exec(3)