Sys.command renvoie le code d'erreur de la commande

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2219 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1998-12-02 16:11:37 +00:00
parent 7f9ee6a995
commit 9a436c9b94
1 changed files with 17 additions and 3 deletions

View File

@ -24,6 +24,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#endif
#if !macintosh && !_WIN32
#include <sys/wait.h>
#endif
#include "config.h"
#ifdef HAS_UNISTD
#include <unistd.h>
@ -218,14 +221,25 @@ void sys_init(char **argv)
main_argv = argv;
}
#if !(defined(WIFEXITED) && defined(WEXITSTATUS))
/* Assume old-style V7 status word */
#define WIFEXITED(status) (((status) & 0xFF) == 0)
#define WEXITSTATUS(status) (((status) >> 8) & 0xFF)
#endif
value sys_system_command(value command) /* ML */
{
int status, retcode;
#ifndef _WIN32
int retcode = system(String_val(command));
status = system(String_val(command));
if (WIFEXITED(status))
retcode = WEXITSTATUS(status);
else
retcode = 255;
#else
int retcode = win32_system(String_val(command));
status = retcode = win32_system(String_val(command));
#endif
if (retcode == -1) sys_error(command);
if (status == -1) sys_error(command);
return Val_int(retcode);
}