home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MN325SRC.ZIP / makenl-3.2.5 / src / osemxexc.c < prev    next >
C/C++ Source or Header  |  2005-02-06  |  2KB  |  70 lines

  1. /* $Id: osemxexc.c,v 1.4 2004/09/05 10:43:57 mbroek Exp $ */
  2.  
  3. #include <process.h>
  4.  
  5. /* spawn sub-process (currently used for compress/decompress tool) */
  6. int os_spawn(const char *command, const char *cmdline)
  7. {
  8.     char execfn[_MAX_PATH];
  9.     char tmpfn[_MAX_PATH];
  10.     char *pext;
  11.     char *cmd;
  12.     int rc;
  13.  
  14.     /* search for command */
  15.     strcpy(tmpfn, command);
  16.     pext = strchr(tmpfn, '\0');
  17.  
  18.     Debug1("os_spawn: trying `%s'\n", tmpfn);
  19.     mklog(4, "os_spawn: trying `%s'", tmpfn);
  20.     rc = _path(execfn, tmpfn);
  21.     if (rc != 0)
  22.     {
  23.         strcpy(pext, ".EXE");
  24.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  25.     mklog(4, "os_spawn: trying `%s'", tmpfn);
  26.         rc = _path(execfn, tmpfn);
  27.     }
  28.     else if (rc != 0 && _osmode == OS2_MODE)
  29.     {
  30.         strcpy(pext, ".CMD");
  31.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  32.     mklog(4, "os_spawn: trying `%s'", tmpfn);
  33.         rc = _path(execfn, tmpfn);
  34.     }
  35.     else if (rc != 0 && _osmode != OS2_MODE)
  36.     {
  37.         strcpy(pext, ".COM");
  38.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  39.     mklog(4, "os_spawn: trying `%s'", tmpfn);
  40.         rc = _path(execfn, tmpfn);
  41.     }
  42.     else if (rc != 0 && _osmode != OS2_MODE)
  43.     {
  44.         strcpy(pext, ".BAT");
  45.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  46.     mklog(4, "os_spawn: trying `%s'", tmpfn);
  47.         rc = _path(execfn, tmpfn);
  48.     }
  49.     else if (rc != 0)
  50.     {
  51.         printf("os_spawn: program not found\n");
  52.     mklog(0, "os_spawn: program not found");
  53.         return -1;
  54.     }
  55.  
  56.     cmd = malloc(strlen(command) + 1 + strlen(cmdline) + 1);
  57.     if (!cmd)
  58.         return -1;
  59.  
  60.     sprintf(cmd, "%s %s", command, cmdline);
  61.     Debug1("found: executing `%s'\n", cmd);
  62.     mklog(3, "found: executing `%s'", cmd);
  63.     rc = system(cmd);
  64.     Debug1("os_spawn rc=%d\n", rc);
  65.     mklog(3, "os_spawn rc=%d", rc);
  66.  
  67.     free(cmd);
  68.     return rc;
  69. }
  70.