00001 #include <stdlib.h>
00002 #include <unistd.h>
00003 #include <sys/types.h>
00004 #ifndef __MINGW32__
00005 #include <sys/wait.h>
00006 #endif
00007 #include <grass/gis.h>
00008 #include <grass/glocale.h>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <signal.h>
00028 #include <stdio.h>
00029
00030
00046 int G_system ( char *command)
00047 {
00048 int status, pid, w;
00049 void (*sigint)()
00050 #ifdef SIGQUIT
00051 , (*sigquit)()
00052 #endif
00053 ;
00054
00055 sigint = signal (SIGINT, SIG_IGN);
00056 #ifdef SIGQUIT
00057 sigquit = signal (SIGQUIT, SIG_IGN);
00058 #endif
00059
00060 fflush (stdout);
00061 fflush (stderr);
00062
00063 #ifdef __MINGW32__
00064 signal (SIGINT, SIG_DFL);
00065 _spawnl ( P_WAIT,
00066 "command",
00067 "command",
00068 "/c",
00069 command,
00070 NULL );
00071 #else
00072 if ( (pid = fork()) == 0)
00073 {
00074 signal (SIGINT, SIG_DFL);
00075 signal (SIGQUIT, SIG_DFL);
00076
00077 execl ("/bin/sh", "sh", "-c", command, NULL);
00078 _exit(127);
00079 }
00080
00081 if (pid < 0)
00082 {
00083 G_warning (_("Can not create a new process!"));
00084 status = -1;
00085 }
00086 else
00087 {
00088 while ( (w = wait (&status)) != pid && w != -1);
00089
00090 if (w == -1)
00091 status = -1;
00092 }
00093
00094 #endif
00095
00096 signal (SIGINT, sigint);
00097 #ifdef SIGQUIT
00098 signal (SIGQUIT, sigquit);
00099 #endif
00100
00101 return (status);
00102 }