Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/system.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/system.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/system.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/system.html on line 8

system()

Execute a system command

Synopsis:

#include <stdlib.h>

int system( const char *command );

Arguments:

command
NULL, or the system command that you want to execute; see below.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The behavior of the system() function depends on the value of its command argument:


Note: The shell used is always /bin/sh, regardless of the setting of the SHELL environment variable, because applications may rely on features of the standard shell, and may fail as a result of running a different shell.

This means that any command that can be entered to the OS can be executed, including programs, QNX Neutrino commands, and shell scripts. The exec*() and spawn*() functions can only cause programs to be executed.


Returns:

For information about macros that extract information from the value returned by system(), see Status macros in the description of wait().

When an error has occurred, errno contains a value that indicates the type of error that has been detected.

Examples:

#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>

int main( void )
  {
    int rc;

    rc = system( "ls" );
    if( rc == -1 ) {
      printf( "shell could not be run\n" );
    } else {
      printf( "result of running command is %d\n",
          WEXITSTATUS( rc ) );
    }
    return EXIT_SUCCESS;
  }

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

abort(), atexit(), close(), errno, execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), exit(), _exit(), getenv(), main(), putenv(), sigaction(), signal(), spawn(), spawnl(), spawnle(), spawnlp(), spawnlpe(), spawnp(), spawnv(), spawnve(), spawnvp(), spawnvpe(), wait(), waitpid()

Processes and Threads chapter of Getting Started with QNX Neutrino


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/system.html on line 237

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/system.html on line 237