Go to the documentation of this file.00001
00017 #include <grass/config.h>
00018 #include <stdlib.h>
00019 #include <unistd.h>
00020 #include <signal.h>
00021 #include <stdio.h>
00022 #include <sys/types.h>
00023 #ifndef __MINGW32__
00024 #include <sys/wait.h>
00025 #endif
00026 #include <grass/gis.h>
00027 #include <grass/glocale.h>
00028
00029
00051 int G_system(const char *command)
00052 {
00053 int status;
00054
00055 #ifndef __MINGW32__
00056 int pid, w;
00057 #endif
00058 RETSIGTYPE(*sigint) ();
00059 #ifdef SIGQUIT
00060 RETSIGTYPE(*sigquit) ();
00061 #endif
00062
00063 sigint = signal(SIGINT, SIG_IGN);
00064 #ifdef SIGQUIT
00065 sigquit = signal(SIGQUIT, SIG_IGN);
00066 #endif
00067
00068 fflush(stdout);
00069 fflush(stderr);
00070
00071 #ifdef __MINGW32__
00072 signal(SIGINT, SIG_DFL);
00073 _spawnlp(P_WAIT, "cmd.exe", "cmd.exe", "/c", command, NULL);
00074 status = 0;
00075 #else
00076 if ((pid = fork()) == 0) {
00077 signal(SIGINT, SIG_DFL);
00078 signal(SIGQUIT, SIG_DFL);
00079
00080 execl("/bin/sh", "sh", "-c", command, NULL);
00081 _exit(127);
00082 }
00083
00084 if (pid < 0) {
00085 G_warning(_("Can not create a new process!"));
00086 status = -1;
00087 }
00088 else {
00089 while ((w = wait(&status)) != pid && w != -1) ;
00090
00091 if (w == -1)
00092 status = -1;
00093 }
00094
00095 #endif
00096
00097 signal(SIGINT, sigint);
00098 #ifdef SIGQUIT
00099 signal(SIGQUIT, sigquit);
00100 #endif
00101
00102 return (status);
00103 }