@@ -2330,55 +2330,71 @@ static int rb_exec_without_timer_thread(const struct rb_execarg *eargp, char *er
2330
2330
* call-seq:
2331
2331
* exec([env,] command... [,options])
2332
2332
*
2333
- * Replaces the current process by running the given external _command_.
2334
- * _command..._ is one of following forms.
2333
+ * Replaces the current process by running the given external _command_, which
2334
+ * can take one of the following forms:
2335
2335
*
2336
- * commandline : command line string which is passed to the standard shell
2337
- * cmdname, arg1, ... : command name and one or more arguments (no shell)
2338
- * [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
2336
+ * [<code>exec(commandline)</code>]
2337
+ * command line string which is passed to the standard shell
2338
+ * [<code>exec(cmdname, arg1, ...)</code>]
2339
+ * command name and one or more arguments (no shell)
2340
+ * [<code>exec([cmdname, argv0], arg1, ...)</code>]
2341
+ * command name, argv[0] and zero or more arguments (no shell)
2342
+ *
2343
+ * In the first form, the string is taken as a command line that is subject to
2344
+ * shell expansion before being executed.
2345
+ *
2346
+ * The standard shell always means <code>"/bin/sh"</code> on Unix-like systems,
2347
+ * same as <code>ENV["RUBYSHELL"]</code>
2348
+ * (or <code>ENV["COMSPEC"]</code> on Windows NT series), and similar.
2349
+ *
2350
+ * If the string from the first form (<code>exec("command")</code>) follows
2351
+ * these simple rules:
2339
2352
*
2340
- * If single string is given as the command,
2341
- * it is taken as a command line that is subject to shell expansion before being executed.
2353
+ * * no meta characters
2354
+ * * no shell reserved word and no special built-in
2355
+ * * Ruby invokes the command directly without shell
2356
+ *
2357
+ * You can force shell invocation by adding ";" to the string (because ";" is
2358
+ * a meta character).
2342
2359
*
2343
- * The standard shell means always <code>"/bin/sh"</code> on Unix-like systems,
2344
- * <code>ENV["RUBYSHELL"]</code> or <code>ENV["COMSPEC"]</code> on Windows NT series, and
2345
- * similar.
2346
- * If _commandline_ is simple enough,
2347
- * no meta characters, no shell reserved word and no special built-in,
2348
- * Ruby invokes the command directly without shell.
2349
- * You can force shell invocation by adding ";" for _commandline_ (because ";" is a meta character).
2350
2360
* Note that this behavior is observable by pid obtained
2351
- * (return value of spawn() and IO#pid for IO.popen) is the pid of the invoked command, not shell.
2361
+ * (return value of spawn() and IO#pid for IO.popen) is the pid of the invoked
2362
+ * command, not shell.
2352
2363
*
2353
- * If two or more +string+ given,
2354
- * the first is taken as a command name and
2355
- * the rest are passed as parameters to command with no shell expansion.
2364
+ * In the second form (<code>exec("command1", "arg1", ...)</code>), the first
2365
+ * is taken as a command name and the rest are passed as parameters to command
2366
+ * with no shell expansion.
2356
2367
*
2357
- * If a two-element array at the beginning of the command ,
2358
- * the first element is the command to be executed,
2359
- * and the second argument is used as the <code>argv[0]</code> value,
2360
- * which may show up in process listings.
2368
+ * In the third form (<code>exec(["command", "argv0"], "arg1", ...)</code>) ,
2369
+ * starting a two- element array at the beginning of the command, the first
2370
+ * element is the command to be executed, and the second argument is used as
2371
+ * the <code>argv[0]</code> value, which may show up in process listings.
2361
2372
*
2362
- * In order to execute the command, one of the <code>exec(2)</code>
2363
- * system calls is used, so the running command may inherit some of the environment
2373
+ * In order to execute the command, one of the <code>exec(2)</code> system
2374
+ * calls are used, so the running command may inherit some of the environment
2364
2375
* of the original program (including open file descriptors).
2365
- * This behavior is modified by env and options.
2366
- * See <code>spawn</code> for details.
2367
2376
*
2368
- * Raises SystemCallError if the command couldn't execute (typically
2369
- * <code>Errno::ENOENT</code> when it was not found).
2377
+ * This behavior is modified by the given +env+ and +options+ parameters. See
2378
+ * ::spawn for details.
2379
+ *
2380
+ * If the command fails to execute (typically <code>Errno::ENOENT</code> when
2381
+ * it was not found) a SystemCallError exception is raised.
2382
+ *
2383
+ * This method modifies process attributes according to given +options+ before
2384
+ * <code>exec(2)</code> system call. See ::spawn for more details about the
2385
+ * given +options+.
2370
2386
*
2371
- * This method modifies process attributes according to _options_
2372
- * (details described in <code>spawn</code>)
2373
- * before <code>exec(2)</code> system call.
2374
- * The modified attributes may be retained when <code>exec(2)</code> system call fails.
2375
- * For example, hard resource limits is not restorable.
2376
- * If it is not acceptable, consider to create a child process using <code>spawn</code> or <code>system</code>.
2387
+ * The modified attributes may be retained when <code>exec(2)</code> system
2388
+ * call fails.
2389
+ *
2390
+ * For example, hard resource limits are not restorable.
2391
+ *
2392
+ * Consider to create a child process using ::spawn or Kernel#system if this
2393
+ * is not acceptable.
2377
2394
*
2378
2395
* exec "echo *" # echoes list of files in current directory
2379
2396
* # never get here
2380
2397
*
2381
- *
2382
2398
* exec "echo", "*" # echoes an asterisk
2383
2399
* # never get here
2384
2400
*/
0 commit comments