home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / process / dosexec.txh < prev    next >
Encoding:
Text File  |  1996-09-08  |  4.7 KB  |  110 lines

  1. @node spawn*, process
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <process.h>
  6.  
  7. int spawnl(int mode, const char *path, const char *argv0, ...);
  8. int spawnle(int mode, const char *path, const char *argv0, ... /*, const char **envp */);
  9. int spawnlp(int mode, const char *path, const char *argv0, ...);
  10. int spawnlpe(int mode, const char *path, const char *argv0, ... /*, const char **envp */);
  11.  
  12. int spawnv(int mode, const char *path, const char **argv);
  13. int spawnve(int mode, const char *path, const char **argv, const char **envp);
  14. int spawnvp(int mode, const char *path, const char **argv);
  15. int spawnvpe(int mode, const char *path, const char **argv, const char **envp);
  16. @end example
  17.  
  18. @subheading Description
  19.  
  20. These functions run other programs.  The @var{path} points to the
  21. program to run.  The extension is optional---if not given, and
  22. @var{path} is not found neither in the current directly nor along the
  23. @samp{PATH}, the extensions @file{.com}, @file{.exe}, @file{.bat},
  24. @file{.btm}, @file{.sh}, and @file{.ksh} are checked.  @file{.com}
  25. programs are invoked via the usual DOS calls; DJGPP @file{.exe} programs
  26. are invoked in a way that allows long command lines to be passed; other
  27. @file{.exe} programs are invoked via DOS; @file{.bat} and @file{.btm}
  28. programs are invoked via the command processor given by the
  29. @samp{COMSPEC} environment variable; @file{.sh}, @file{.ksh} programs
  30. and programs with any other extensions that have @code{#!} as their
  31. first two caharacters are assumed to be Unix-style scripts and are
  32. invoked by calling a program whose pathname immediately follows the
  33. first two characters.  (If the name of that program is a Unix-style
  34. pathname, without a drive letter and without an extension, like
  35. @samp{/bin/sh}, the @code{spawn} functions will additionally look them
  36. up on the @samp{PATH}; this allows to run Unix scripts without editing,
  37. if you have a shell installed somewhere along your @samp{PATH}.)
  38.  
  39. Note that built-in commands of the shells can @emph{not} be invoked via
  40. these functions; use @code{system} instead.
  41.  
  42. The programs are invoked with the arguments given.  The zeroth argument
  43. is normally not used, since MS-DOS cannot pass it separately.  There are
  44. two ways of passing arguments.  The @code{l} functions (like
  45. @code{spawnl}) take a list of arguments, with a zero at the end of the
  46. list.  This is useful when you know how many argument there will be
  47. ahead of time.  The @code{v} functions (like @code{spawnv}) take a
  48. pointer to a list of arguments.  This is useful when you need to compute
  49. the number of arguments at runtime. 
  50.  
  51. In either case, you may also specify @code{e} to indicate that you will
  52. be giving an explicit environment, else the current environment is used. 
  53. You may also specify @code{p} to indicate that you would like
  54. @code{spawn*} to search the PATH (in either the environment you pass or
  55. the current environment) for the executable, else it will only check the
  56. explicit path given. 
  57.  
  58. Note that these function understand about other DJGPP programs, and will
  59. call them directly, so that you can pass command lines longer than 126
  60. characters to them without any special code.  DJGPP programs called by
  61. these functions will @emph{not} glob the arguments passed to them; other
  62. programs also won't glob the arguments if they suppress expansion when
  63. given quoted filenames.
  64.  
  65. @xref{exec*}.
  66.  
  67. @subheading Return Value
  68.  
  69. If successful and @code{mode} is @code{P_WAIT}, these functions return
  70. the exit code of the child process in the lower 8 bits of the return
  71. value.  Note that if the program is run by a command processor (e.g., if
  72. it's a batch file), the exit code of that command processor will be
  73. returned.  @file{COMMAND.COM} is notorious for returning 0 even if it
  74. couldn't run the command.
  75.  
  76. If successful and @var{mode} is @code{P_OVERLAY}, these functions will
  77. not return. 
  78.  
  79. If there is an error (e.g., the program specified as @code{argv[0]}
  80. cannot be run, or the command line is too long), these functions return
  81. -1 and set @code{errno} to indicate the error.  If the child program was
  82. interrupted by @key{Ctrl-C} or a Critical Device error, @code{errno} is
  83. set to @code{EINTR} (even if the child's exit code is 0), and bits 8-17
  84. of the return value are set to @code{SIGINT} or @code{SIGABRT},
  85. accordingly.  Note that you must set the signal handler for
  86. @code{SIGINT} to @code{SIG_IGN}, or arrange for the handler to return,
  87. or else your program will be aborted before it will get chance to set
  88. the value of the return code.
  89.  
  90. @subheading Example
  91.  
  92. @example
  93.  
  94. char *environ[] = @{
  95.   "PATH=c:\\dos;c:\\djgpp;c:\\usr\\local\\bin",
  96.   "DJGPP=c:/djgpp",
  97.   0
  98. @};
  99.  
  100. char *args[] = @{
  101.   "gcc",
  102.   "-v",
  103.   "hello.c",
  104.   0
  105. @};
  106.  
  107. spawnvpe(P_WAIT, "gcc", args, environ);
  108. @end example
  109.  
  110.