SYSTEM(3) BSD Library Functions Manual SYSTEM(3)NAME
system -- pass a command to the shell
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
int
system(const char *string);
DESCRIPTION
The system() function hands the argument string to the command interpreter sh(1). The calling process waits for the shell to finish execut-
ing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.
If string is a NULL pointer, system() will return non-zero, if the command interpreter is available, or zero if none is available. Other-
wise, system() returns the termination status of the shell in the format specified by waitpid(2).
RETURN VALUES
If a child process cannot be created, or the termination status of the shell cannot be obtained, system() returns -1 and sets errno to indi-
cate the error. If execution of the shell fails, system() returns the termination status for a program that terminates with a call of
exit(127).
SEE ALSO sh(1), execve(2), waitpid(2), popen(3), shquote(3)STANDARDS
The system() function conforms to ANSI X3.159-1989 (``ANSI C89'') and IEEE Std 1003.2-1992 (``POSIX.2'').
CAVEATS
Never supply the system() function with a command containing any part of an unsanitized user-supplied string. Shell meta-characters present
will be honored by the sh(1) command interpreter.
BSD August 2, 2007 BSD
Check Out this Related Man Page
system(3) Library Functions Manual system(3)NAME
system - Executes a shell command
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <stdlib.h>
int system(
const char *string);
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
system(): XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about industry standards and associated tags.
PARAMETERS
Specifies a valid sh shell command.
If string is NULL (0), the system() function tests the accessibility of the sh command interpreter.
If string is not NULL, the system() function passes the parameter to the sh command, which interprets string as a command and exe-
cutes it.
DESCRIPTION
The system() function passes the string parameter to the sh command, which interprets string as a command and executes it.
The system() function invokes the fork() function to create a child process that in turn uses the exec function to run sh, which interprets
the shell command contained in the string parameter. The current process waits until the shell has completed before returning.
RETURN VALUES
If the string parameter is NULL, the system() function returns 0 if it is unable to access the command interpreter or a non-zero value if
sh is accessible.
If the string parameter is not NULL, upon successful completion by sh, the system() function returns the exit status of the shell process
in the form that wait(2) returns. Otherwise, the system() function returns a value of -1 and sets errno to indicate the error.
Exit status 127 indicates that the shell could not be executed.
Note that the exit status should only be interpreted using the macros described in wait(2) and defined in the sys/wait.h header file.
ERRORS
The system() function sets errno to the specified values for the following conditions: The status of the child process created by system()
is no longer available.
In addition, the system() function may set errno values as described by fork().
RELATED INFORMATION
Functions: exec(2), exit(2), fork(2), wait(2)
Commands: sh(1)
Standards: standards(5) delim off
system(3)
Hi,
I am working on Solaris 8 and the "intro" man page says, "Upon termination, each command returns two bytes of status, one supplied by the system and given the cause for termination, and (in the case of 'normal' termination) one supplied by the program. The former byte is 0 for normal... (2 Replies)
When i try to execute some shell command from my C program using system(), how can I capture the
error that occurs due to the shell command?
The system() command's return values will say if the system() was successfull and not if the shell command is successfull.
When I tested my program, I... (3 Replies)
Hi,
I want to change the login prompt from $ to something more explanatory like
(Username)(basename of pwd):
I also need to get this in a different font color.
Can someone pls tell me what I have to modify in my rc file. I m using CShell currently.
Would be great if u can give me... (7 Replies)
Hello all,
Got a question to ask, in some OS, if a shell command is not an internal command, then it is assumed to be a separate program which is loaded into the memory of the computer and then executed.
In UNIX a different technique is used which does much the same sort of thing. What is the... (2 Replies)
While trying out my hand at writing an interpreter, I was wondering about a a few issues one of which is the following: When I run a command such as jobs in the shell, I get a list of all the background jobs that are running... But if I need my interpreter to run that command, how would I be doing... (34 Replies)
Hi,
I am creating a file in Unix using a shell script. The file is getting created in the Unix - ANSI format. My requirement is to convert it to the PC - ANSI format. Can anyone tell me how to do this?
Thanks,
Sunil (0 Replies)
1. I have a shell script which creates a file using cat command. How can i find what encoding the file follows (e.g. UTF8, ANSI)?
2. I want to convert that file to PC-ANSI format. How can i achieve that?
I tried using the echo $LANG command to find the default encoding. It says parameter not... (2 Replies)
hai friend,
I am new to linux... I have to develop C program using unix command and i know the SYSTEM command.. But i need other then SYSTEM comand, plz send me the sample code....
Thank you..
sundar (1 Reply)
Hello,
i am trying to rename a file X to file Y on different location .
lets say the mv command started but for some reason system crashed while it did not finish.
will file Y be created physically with lets say half the records of what was in file X???
thanks in advance. (2 Replies)
What is the difference between the(a) shell and the (a) command-line interpreter?
Here we're talking about the complete dummy question, but could someone point me right.
(yes, have written scripts in for instance bash shell,
and and grepp-ed my way around ....:eek: (4 Replies)
hey guys!!
please tell me ...how can i use shell meta characters like * ,$ <,> etc in command line
in command line arguments literally
please reply soon ..its urgent!!!! (8 Replies)
The man system says
During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.
What does this mean?
And if i am making a function that does what system does how do i write this signal stuff? (19 Replies)
Hi,
I have hundreds of files "*.out" located in one folder,
and I want to:
1. Identify the good files containing "Normal termination" (grep "Normal termination" *.out )
2. Compress the good files into a tar.gz file (tar cvfz good.tar.gz *.goog.out )
Is there a way I can automate this... (4 Replies)
I am running the gaussian program on UNIX with bash and I want to form a script that will email me once the output life terminates either "normal termination" or "false" I just started learning this last week so could you let me know how to go about this.:b: (13 Replies)