0

我一直在关注 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
4

1 回答 1

2

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

让我们看看enum apr_cmdtype_e

APR_SHELLCMD
使用 shell 调用程序

APR_PROGRAM
直接调用程序,不复制环境

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

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

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

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

于 2012-07-26T21:16:04.027 回答