Thread overview
std.process.system() returns wrong value on linux
Jul 04, 2004
Sam McCall
Related DMD bug (with fix)
Jul 05, 2004
Sam McCall
Jul 06, 2004
Walter
July 04, 2004
From the phobos docs:
int system(char[] command)
    Execute command in a command shell. Returns exit status of command.

The system() function just calls the corresponding C function:
int system(char[] command) {
    return std.c.process.system(toStringz(command));
}

I'm not sure about windows, but on unix system(char*) returns an opaque int that can only be portably accessed using macros defined in sys/wait.h, in particular
WEXITSTATUS(int stat)
gets (the low 8 bits of) the exit status.

This bit me today when I tried to do exit(system(...)) (I didn't know about std.c.exec*...
Sam
July 05, 2004
On linux, if you tell dmd to link against a nonexistant file, it will call gcc to link it, and gcc will return 1. DMD doesn't properly extract the exit status from the result of waitpid, and returns 256 (which is equivalent to 0, as only the low byte is significant).
The fix: (near the end of runLINK() in dmd/link.c)

	waitpid(childpid, &status, 0);

	status=WEXITSTATUS(status); // INSERT THIS LINE

	if (status)
		printf("--- errorlevel %d\n", status);
	return status;

Sam
July 06, 2004
Got it, thanks!