I'm trying to figure out how to do a system()
function call (in C) on SunOS and NOT have anything printed to stderr (or stdout). Currently, the following code compiles/runs on Linux, OSX, HP-UX, and SunOS. On all but SunOS, I get a nice output of something like:
i = 32512 (0x7f00); wexitstatus = 127
But, on SunOS I get:
sh: unknowncommand: not found
i = 256 (0x100); wexitstatus = 1
...that extra "sh:" line is annoying :)
(My goal: quiet programmatic determination of whether or not I can do "cc" and/or "gcc" commands.)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
int main (int argc, char **argv)
{
int i;
char buf [1000];
strcpy (buf, "unknowncommand -c foo.c > /dev/null 2>&1");
i = system (buf);
printf ("i = %d (0x%x); wexitstatus = %d\n", i, i, WEXITSTATUS (i));
return 0;
}