system()

pass command to shell 

Function


SYNOPSIS

#include <stdlib.h>

int system(const char *command);


DESCRIPTION

The system() function passes the string pointed to by command to the host environment so that a command processor can execute it. By passing command as a NULL, system() can inquire whether a command processor exists.

system() causes the string to be given to the shell as input as if the string had been typed as a command at a terminal. The current process waits until the shell has completed then returns the exit status of the shell in the format that waitpid() specifies.

system() ignores the SIGINT and SIGQUIT signals, and blocks the SIGCHLD signal while waiting for the command to terminate. If this might cause the calling process to miss a signal that would have killed it, then the calling process should examine the return value from system() and take whatever action is appropriate to the application if the command terminated due to receipt of a signal.

The system() function will not affect the termination status of any child of the calling processes other than the process or processes it itself creates.

The system() function does not return until the child process has terminated.


PARAMETERS

command 

Points to the string that is passed to the host environment.


RETURN VALUES

If command is a null pointer, system() returns non-zero only if a command processor is available.

If command is not a null pointer, system() returns the termination status of the command language interpreter in the format specified by waitpid(). If some error prevents the command language interpreter from executing after the child process is created, the return value from system() is as if the command language interpreter had terminated using exit(127) or _exit(127). If a child process cannot be created, or if the termination status for the command language interpreter cannot be obtained, system() returns -1 and sets errno to indicate the error:

ECHILD 

Error with the child process

EINVAL 

Invalid command processor.

ENOENT 

No command processor found.


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

There is no default shell in the Window environment. Hence, the NuTCRACKER Platform first checks for SHELL in the environment to determine the shell to use, and then checks COMSPEC for a fall-back command interpreter. If neither is set, then system() fails. The NuTCRACKER Platform implements system() using _NutForkExeclp(); refer to that function for more information on how the command processor is invoked.

You must ensure that any path name arguments you pass to non-NuTCRACKER Platform applications are in Win32 format, as only NuTCRACKER Platform applications recognize the NuTCRACKER Platform format. Refer to Path Names in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for more information.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
_exit(), _NutForkExeclp(), exit(), pclose(), popen(), waitpid()


PTC MKS Toolkit 10.4 Documentation Build 39.