home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / GNUISH / SWALIB0.ZIP / SW_SYS.C < prev    next >
C/C++ Source or Header  |  1990-09-10  |  2KB  |  83 lines

  1. /* sw_sys.c - invoke a shell to execute a command.
  2.    Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3.  
  4.    This file is part of SWAPLIB (the library), a library for efficient
  5.    execution of child processes under MS-DOS.
  6.  
  7.    The library is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 1, or (at your option)
  10.    any later version.
  11.  
  12.    The library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with the library; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.    $Header: e:/gnu/swaplib/RCS/sw_sys.c'v 0.9 90/09/09 21:44:22 tho Stable $
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <errno.h>
  27.  
  28. #include "swaplib.h"
  29.  
  30. extern void *xmalloc (size_t size);
  31.  
  32. int
  33. swap_system (char *command)
  34. {
  35.   char *argv[4];
  36.   char *p = NULL;
  37.  
  38.   /* Find $SHELL or $COMSPEC  */
  39.  
  40.   argv[0] = getenv ("SHELL");
  41.   if (argv[0])
  42.     {
  43.       argv[1] = "-c";
  44.     }
  45.   else
  46.     {
  47.       argv[0] = getenv ("COMSPEC");
  48.       if (argv[0])
  49.     {
  50.       argv[1] = "/c";
  51.     }
  52.       else
  53.     {
  54.       errno = ENOENT;
  55.       return -1;
  56.     }
  57.     }
  58.  
  59.   if (command)
  60.     {
  61.       /* Let the shell execute COMMAND.  */
  62.  
  63.       argv[2] = command;
  64.       argv[3] = NULL;
  65.  
  66.       return swap_spawnvpe (argv[0], argv, NULL);
  67.     }
  68.   else
  69.     {
  70.       /* Just check the existence of a shell.  */
  71.  
  72.       return 0;
  73.     }
  74. }
  75.  
  76. /* 
  77.  * Local Variables:
  78.  * mode:C
  79.  * ChangeLog:ChangeLog
  80.  * compile-command:make
  81.  * End:
  82.  */
  83.