Apache APR函数apr_procattr_cmdtype_set混淆

时间:2012-07-26 05:31:08

标签: c apache

我一直在关注C编码的在线教程,代码正在使用Apache APR库。 它使用apr_proc_t结构来执行外部应用程序。 我对此功能感到困惑,有人可以解释这个功能的含义:

apr_status_t apr_procattr_cmdtype_set   (   apr_procattr_t *    attr,
        apr_cmdtype_e   cmd 
    )       

Set what type of command the child process will call.

Parameters:
    attr    The procattr we care about.
    cmd The type of command. One of:

                APR_SHELLCMD     --  Anything that the shell can handle
                APR_PROGRAM      --  Executable program   (default) 
                APR_PROGRAM_ENV  --  Executable program, copy environment
                APR_PROGRAM_PATH --  Executable program on PATH, copy env

1 个答案:

答案 0 :(得分:2)

apr_procattr_cmdtype_set函数用于告诉APR你想如何执行外部命令,它可能只是设置一个内部标志并进行一些记账。

让我们看一下enum apr_cmdtype_e

  

APR_SHELLCMD
  使用shell来调用程序

     

APR_PROGRAM
  直接调用程序,没有复制的env

     

APR_PROGRAM_ENV
  调用程序,复制我们的环境

     

APR_PROGRAM_PATH
  在PATH上找到程序,使用我们的环境

     

APR_SHELLCMD_ENV
  使用shell来调用程序,复制我们的环境

第一个和最后一个选项(APR_SHELLCMDAPR_SHELLCMD_ENV)几乎说“使用system的可移植版本”(有或没有将当前环境变量复制到新进程) 。其他只是Unix fork / exec对的变体,标志选择要使用的exec系列函数。