GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
system.c
Go to the documentation of this file.
1 
17 #include <grass/config.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <sys/types.h>
23 #ifndef __MINGW32__
24 #include <sys/wait.h>
25 #endif
26 #include <grass/gis.h>
27 #include <grass/glocale.h>
28 
29 
51 int G_system(const char *command)
52 {
53  int status;
54 
55 #ifndef __MINGW32__
56  int pid, w;
57 #endif
58  RETSIGTYPE(*sigint) ();
59 #ifdef SIGQUIT
60  RETSIGTYPE(*sigquit) ();
61 #endif
62 
63  sigint = signal(SIGINT, SIG_IGN);
64 #ifdef SIGQUIT
65  sigquit = signal(SIGQUIT, SIG_IGN);
66 #endif
67 
68  fflush(stdout);
69  fflush(stderr);
70 
71 #ifdef __MINGW32__
72  signal(SIGINT, SIG_DFL);
73  _spawnlp(P_WAIT, "cmd.exe", "cmd.exe", "/c", command, NULL);
74  status = 0;
75 #else
76  if ((pid = fork()) == 0) {
77  signal(SIGINT, SIG_DFL);
78  signal(SIGQUIT, SIG_DFL);
79 
80  execl("/bin/sh", "sh", "-c", command, NULL);
81  _exit(127);
82  }
83 
84  if (pid < 0) {
85  G_warning(_("Can not create a new process!"));
86  status = -1;
87  }
88  else {
89  while ((w = wait(&status)) != pid && w != -1) ;
90 
91  if (w == -1)
92  status = -1;
93  }
94 
95 #endif
96 
97  signal(SIGINT, sigint);
98 #ifdef SIGQUIT
99  signal(SIGQUIT, sigquit);
100 #endif
101 
102  return (status);
103 }
list command
Definition: render.py:1315
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_system(const char *command)
Run a shell level command.
Definition: system.c:51
Definition: spawn.c:69