X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=usystem.c;h=23b798b784bac70c393a0daed72daad259f67b28;hb=de1e5c90f7dc200af953878230331fefe4b38ed7;hp=23ba305799bc93e6851b794c8a00fabdb87a054a;hpb=b8fda05a14b77f791e9646ffd715210aab0e9261;p=xboard.git diff --git a/usystem.c b/usystem.c index 23ba305..23b798b 100644 --- a/usystem.c +++ b/usystem.c @@ -516,6 +516,22 @@ DestroyChildProcess (ProcRef pr, int signalType) close(cp->fdTo); } +char * +BufferCommandOutput (char *command, int size) +{ + ChildProc *pr; + char *res = (char *) calloc(1, size); + if(res) { + int count; + StartChildProcess(command, ".", (ProcRef) &pr); // run command in daughter process + count = read(pr->fdFrom, res, size-1); // read its output + res[count > 0 ? count : 0] = NULLCHAR; + DestroyChildProcess((ProcRef) pr, 9); + free(pr); + } + return res; // return buffer with output +} + void InterruptChildProcess (ProcRef pr) {