2012-07-26 50 views
0

我一直在線上關於C編程的教程,並且代碼使用的是Apache APR庫。 它使用apr_proc_t結構來執行外部應用程序。 我很困惑這個功能,可能有人解釋這是什麼功能是指:Apache APR函數apr_procattr_cmdtype_set混淆

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 

回答

2

apr_procattr_cmdtype_set功能是用來告訴APR要如何執行外部命令,它可能只是設置一個內部標誌,並且有點簿記。

讓我們看看enum apr_cmdtype_e

APR_SHELLCMD
使用shell來調用程序

APR_PROGRAM
調用該程序直接,沒有複製ENV

APR_PROGRAM_ENV
調用該計劃,複製我們的環境

APR_PROGRAM_PATH
上查找路徑方案,

第一和最後一個選項(APR_SHELLCMDAPR_SHELLCMD_ENV)相當使用我們的環境

APR_SHELLCMD_ENV
使用shell來調用程序,複製我們的環境多說「使用system的便攜版本」(有或沒有將當前環境變量複製到新進程中)。其他的只是Unix的fork/exec對中的變體,其中的標誌選擇要使用的exec系列函數中的哪一個。

+0

謝謝你的回答。 – ArmenB 2012-08-01 07:08:47