home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MNLDOS.ZIP / src / osemxexc.c < prev    next >
C/C++ Source or Header  |  2004-07-11  |  2KB  |  62 lines

  1. /* $Id: osemxexc.c,v 1.2 2004/07/11 09:29:14 ozzmosis 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.     rc = _path(execfn, tmpfn);
  20.     if (rc != 0)
  21.     {
  22.         strcpy(pext, ".EXE");
  23.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  24.         rc = _path(execfn, tmpfn);
  25.     }
  26.     else if (rc != 0 && _osmode == OS2_MODE)
  27.     {
  28.         strcpy(pext, ".CMD");
  29.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  30.         rc = _path(execfn, tmpfn);
  31.     }
  32.     else if (rc != 0 && _osmode != OS2_MODE)
  33.     {
  34.         strcpy(pext, ".COM");
  35.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  36.         rc = _path(execfn, tmpfn);
  37.     }
  38.     else if (rc != 0 && _osmode != OS2_MODE)
  39.     {
  40.         strcpy(pext, ".BAT");
  41.         Debug1("os_spawn: trying `%s'\n", tmpfn);
  42.         rc = _path(execfn, tmpfn);
  43.     }
  44.     else if (rc != 0)
  45.     {
  46.         printf("os_spawn: program not found\n");
  47.         return -1;
  48.     }
  49.  
  50.     cmd = malloc(strlen(command) + 1 + strlen(cmdline) + 1);
  51.     if (!cmd)
  52.         return -1;
  53.  
  54.     sprintf(cmd, "%s %s", command, cmdline);
  55.     Debug1("found: executing `%s'\n", cmd);
  56.     rc = system(cmd);
  57.     Debug1("os_spawn rc=%d\n", rc);
  58.  
  59.     free(cmd);
  60.     return rc;
  61. }
  62.