22.3.2 Core API for program execution

Function: mbfl_program_exec PROGRAM ARG

Evaluate a command line. PROGRAM identifies an executable file: it can be the program name, or a relative or absolute pathname. The optional ARG values are command line arguments that are handed to the program unchanged.

If usage of sudo was requested, the command is executed with it; then the sudo request is reset. This means that this function “consumes” a sudo request. Executing programs with another’s profile privileges.

If the redirection of stderr to stdout is requested with mbfl_program_redirect_stderr_to_stdout(): such request is honoured and consumed. For a discussion of channels redirection when calling this function, see Redirecting channels when executing a program.

If the function mbfl_program_set_exec_flags() was used to select arguments for the Bash built–in exec: that request is ignored and reset.

If the function mbfl_option_test() returns true: instead of evaluation, the command line is sent to stderr.

If the function mbfl_option_show_program() returns true: the command line is sent to stderr, then it is executed.

Function: mbfl_program_exec2 INFD OUFD ERFD PROGRAM ARG

Like mbfl_program_exec(), but redirect the standard input, output and error channels using the given file descriptors.

local -ir INFD=10 OUFD=11 ERFD=12

mbfl_fd_open_input  $INFD /some/file
mbfl_fd_open_output $OUFD /another/file
mbfl_fd_open_output $ERFD /yet/another/file
mbfl_program_exec2 $INFD $OUFD $ERFD /some/program.exe --some-option SOME_ARG

If the redirection of stderr to stdout is requested with mbfl_program_redirect_stderr_to_stdout(): such request is ignored and consumed. For a discussion of channels redirection when calling this function, see Redirecting channels when executing a program.


This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.