1 /**************************************************************************/
2 /*                                                                        */
3 /*                                 OCaml                                  */
4 /*                                                                        */
5 /*   Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt     */
6 /*                                                                        */
7 /*   Copyright 1996 Institut National de Recherche en Informatique et     */
8 /*     en Automatique.                                                    */
9 /*                                                                        */
10 /*   All rights reserved.  This file is distributed under the terms of    */
11 /*   the GNU Lesser General Public License version 2.1, with the          */
12 /*   special exception on linking described in the file LICENSE.          */
13 /*                                                                        */
14 /**************************************************************************/
15 
16 #include <caml/mlvalues.h>
17 #include <caml/memory.h>
18 #include <caml/alloc.h>
19 #include <caml/signals.h>
20 #include "unixsupport.h"
21 #include <process.h>
22 #include <stdio.h>
23 
win_system(cmd)24 CAMLprim value win_system(cmd)
25      value cmd;
26 {
27   int ret;
28   value st;
29   char *buf;
30   intnat len;
31 
32   caml_unix_check_path(cmd, "system");
33   len = caml_string_length (cmd);
34   buf = caml_stat_alloc (len + 1);
35   memmove (buf, String_val (cmd), len + 1);
36   caml_enter_blocking_section();
37   _flushall();
38   ret = system(buf);
39   caml_leave_blocking_section();
40   caml_stat_free(buf);
41   if (ret == -1) uerror("system", Nothing);
42   st = caml_alloc_small(1, 0); /* Tag 0: Exited */
43   Field(st, 0) = Val_int(ret);
44   return st;
45 }
46