Symisc Systems

Libcox C/C++ API Reference - Libcox Command Executions


Star Follow @symisc

Syntax

int libcox_exec(libcox *pHandle,libcox_value **ppOut,const char *zCmd,int nLen);

int libcox_exec_fmt(libcox *pHandle,libcox_value **ppOut,const char *zFmt,...);


Execute one or more commands and extract the processing result.

Description

Execute one or libcox commands. After successful execution, the execution result (i.e. The return value) of the last processed command is stored in the ppOut parameter. Call libcox_value_to_string(), libcox_value_to_int64(), etc. to extract the processing result.

Multiple commands can be executed in a single call via this interface by separating the target commands with a semi-colon ';' as follows: libcox_exec(pHandle,&pOut,"chdir /home/me/desktop ; mkdir test",-1);

In case where multiple commands are executed via this interface, it is recommended that you install a command output consumer callback to process the return value of the multiple commands rather than working with the ppOut parameter which store the value of the last executed command only. This operation can be done via libcox_config() with a configuration verb set to: LIBCOX_CONFIG_OUTPUT_CONSUMER.

libcox_exec_fmt() is a work-alike of the "printf()" family of functions from the standard C library which is used to execute a small formatted string as follows:
libcox_exec_fmt(pHandle,&pOut,"mkdir %s",zDir);

Tip: Refer to the download page for some C/C++ samples on how to work with these interfaces.


Parameters

pHandle

Libcox Handle obtained a prior successful call to libcox_init().

ppOut

OUT: The execution result of the last executed commands is stored here. Call libcox_value_to_string(), libcox_value_to_int64(), etc. to extract the processing result. Pass NULL if you do not need the return value of the command.

zCmd

One or more commands to execute.

nLen

zCmd length if available. Otherwise pass -1.


Return value

LIBCOX_OK is returned on success and the processing result is pointed by the ppOut parameter for later extraction. Any other return value indicates failure.


See also

libcox_release, libcox_init, libcox_exec_result_destroy, libcox_config.