December 2005
Beginner to intermediate
618 pages
20h 19m
English
system
Executes a shell command
#include <stdlib.h> intsystem( const char *s);
The system() function
passes a command line addressed by the pointer argument
s to an operating system shell. If
s is a null pointer, the function returns
true (a nonzero value) if a
command processor is available to handle shell commands, and 0 or
false if not.
How the system executes a command, and what value the system() function returns, are left up to
the given implementation. The command may terminate the program that
calls system(), or have
unspecified effects on its further behavior.
if ( system( NULL ))system( "echo \"Shell: $SHELL; process ID: $$\"");
else
printf( "No command processor available.\n" );This example is not portable, but on certain systems it can produce output like this:
Shell: /usr/local/bin/bash; process ID: 21349
Read now
Unlock full access