Pointer to a null-terminated string containing the command to be executed by the host environment's command processor. If this is `NULL`, the function simply checks for the availability of a command processor.
Read more about parameters of system in parameters section
The systemfunction in C language Executes a command string in a command processor or shell.
The system function passes the command string to the host environment to be executed by a command processor. The command is executed in a separate process, and the calling process waits for its completion. This function provides a way to execute system commands from within a C program.
The systemfunction takes 1
parameter:
•
const char * `command`: Pointer to a null-terminated string containing the command to be executed by the host environment's command processor. If this is `NULL`, the function simply checks for the availability of a command processor.
Executes the command specified by the string `command` in a new process, using the host environment's command processor. If `command` is `NULL`, the function returns a nonzero value if a command processor is available, or `0` otherwise. Returns the exit status of the command or `-1` if a new process could not be created.
The system function return value :
If command is NULL, returns nonzero if a command processor is available
If command is not NULL, returns the exit status of the command executed (implementation-defined)
If a child process could not be created or its status could not be retrieved, -1 is returned
Output
This example demonstrates basic usage of system to execute the 'ls -l' command on a Unix-like system. It also checks the return value to determine if the command was executed successfully.