Functions of system functions in VC

Source: Internet
Author: User
Tags compact

System, _ wsystem

Execute a command.

Int System ( Const Char *Command );

Int _ Wsystem ( Const Wchar_t *Command );

Routine Required Header Compatibility
System <Process. h> or <stdlib. h> ANSI, Win 95, Win NT
_ Wsystem <Process. h> or <stdlib. h> or <wchar. h> Win NT

For additional compatibility information, seeCompatibilityIn the introduction.

Libraries

LIBC. LIB Single thread static library, retail version
LIBCMT. LIB Multithread static library, retail version
MSVCRT. LIB Import library for MSVCRT. DLL, retail version

Return Value

IfCommandIsNULLAnd the command interpreter is found, the function returns a nonzero value. If the command interpreter is not found, it returns 0 and setsErrnoToENOENT. IfCommandIs notNULL,SystemReturns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of-1 indicates an error, andErrnoIs set to one of the following values:

E2BIG

Argument list (which is system-dependent) is too big.

ENOENT

Command interpreter cannot be found.

ENOEXEC

Command-interpreter file has Invalid format and is not executable.

ENOMEM

Not enough memory is available to execute command; or available memory has been expired upted; or invalid block exists, indicating that process making call was not allocated properly.

Parameter

Command

Command to be executed

Remarks

TheSystemFunction passesCommandTo the command interpreter, which executes the string as an operating-system command.SystemRefers toCOMSPECAndPATHEnvironment variables that locate the command-interpreter file (the file named CMD. EXE in Windows NT). IfCommandIs NULL, the function simply checks to see whether the command interpreter exists.

You must explicitly flush (usingFflushOr_ Flushall) Or close any stream before callingSystem.

_ WsystemIs a wide-character versionSystem;CommandArgument_ WsystemIs a wide-character string. These functions behave identically otherwise.

Generic-text routine Mappings

TCHAR. H Routine _ UNICODE & _ MBCS Not Defined _ MBCS Defined _ UNICODE Defined
_ Tsystem System System _ Wsystem

Example

/* SYSTEM.C: This program uses * system to TYPE its source file. */#include <process.h>void main( void ){   system( "type system.c" );}

Output

/* SYSTEM.C: This program uses * system to TYPE its source file. */#include <process.h>void main( void ){   system( "type system.c" );}
 

As long as executable programs and operating system commands can be used as parameters, there is no edge.

 

Std: system("Cls");Clear Screen
Std: system
("Color fc");Set color

 

 

The system function can call some DOS commands, such
System ("CLS"); // clear screen, equivalent to using the CLS command on DoS
The following lists common DOS commands that can be called using the system function:


Assoc displays or modifies file extension associations.
At is the command and program to be run on the computer.
Attrib displays or changes file attributes.
Set or clear the extended Ctrl + C check.
Cacls displays or modifies the File Access Control List (ACLs ).
Call calls this one from another batch processing program.
CD displays or changes the name of the current directory.
Chcp displays or sets the number of pages of the active code.
Chdir displays or changes the name of the current directory.
Chkdsk checks the disk and displays the status report.
CHKNTFS Displays or modifies the boot time disk check.
CLS clears the screen.
CMD opens another Windows Command Interpreter window.
COLOR sets the default console foreground and background COLOR.
COMP compares the content of two or two sets of files.
COMPACT Displays or changes the compression of files on NTFS partitions.
CONVERT Converts a FAT volume to NTFS. You cannot convert
Current Drive.
COPY Copies at least one file to another location.
DATE: displays or sets the DATE.
DEL deletes at least one file.
DIR Displays files and subdirectories in a directory.
DISKCOMP compares two floppy disks.
DISKCOPY copies the content of one floppy disk to another.
DOSKEY: edit the command line, call the Windows Command, and create a macro.
ECHO Displays the message, or explicitly opens or closes the command.
ENDLOCAL ends the localization of Environment Changes in the batch file.
ERASE deletes at least one file.
EXIT to EXIT the CMD. EXE program (command interpreter ).
FC compares two or two sets of files and displays
Different Places.
FIND searches for text strings in the file.
FINDSTR searches for strings in the file.
FOR runs a specified command FOR each file in a set of files.
FORMAT the disk for use with Windows.
FTYPE Displays or modifies the file type associated with the file extension.
GOTO direct the Windows command interpreter to a batch processing program
Is specified.
GRAFTABL enables Windows to display images
Extended character set.
HELP provides HELP information for Windows commands.
IF executes conditional processing in the batch processing program.
LABEL to create, change, or delete the volume LABEL of a disk.
MD creates a directory.
Create a directory using MKDIR.
MODE: configure the system device.
MORE: display a result screen at a time.
MOVE Moves the file from one directory to another.
PATH: displays or sets the search PATH for executable files.
PAUSE Suspends processing of batch files and displays messages.
POPD restores the previous value of the current directory saved by PUSHD.
PRINT a text file.
PROMPT to change the Windows command PROMPT.
PUSHD saves the current directory and changes it.
RD deletes the directory.
RECOVER restores readable information from the faulty disk.
REM record comments in a batch file or CONFIG. SYS.
Rename the file.
RENAME the file.
REPLACE the file.
Delete the RMDIR directory.
SET displays, sets, or deletes Windows environment variables.
SETLOCAL starts localization of Environment Changes in the batch file.
SHIFT changes the positions of parameters that can be replaced in a batch file.
SORT classifies input.
START starts another window to run the specified program or command.
SUBST Associates the path with a drive letter.
TIME: displays or sets the system TIME.
TITLE: Set the TITLE of the CMD. EXE session.
TREE displays the directory structure of the drive or path in graphic mode.
TYPE: displays the content of a text file.
Server displays the Windows version.
VERIFY tells Windows whether to VERIFY that the file is correct
Write Data to the disk.
VOL Displays the volume label and serial number of the disk.
XCOPY copies the file and directory tree.


**************************************** **********************************

Use of the system () function in c ++ 2008-07-17 15: 57int system (const char * command );
Int _ wsystem (const wchar_t * command );

Command: Command to be executed

Sample :''''''''''''''
// System. c
# Include <process. h>

Void main (void)
{
System ("type system. c ");
}


The system function can call some DOS commands, such
System ("cls"); // clear screen, equivalent to using the cls command on DOS
The following lists common DOS commands that can be called using the system function:


ASSOC displays or modifies file extension associations.
AT is the command and program to be run on the computer.
ATTRIB displays or changes file attributes.
Set or clear the extended CTRL + C check.
CACLS displays or modifies the File Access Control List (ACLs ).
CALL calls this one from another batch processing program.
CD displays or changes the name of the current directory.
CHCP displays or sets the number of pages of the active code.
CHDIR displays or changes the name of the current directory.
CHKDSK checks the disk and displays the status report.
CHKNTFS Displays or modifies the boot time disk check.
CLS clears the screen.
CMD opens another Windows Command Interpreter window.
COLOR sets the default console foreground and background COLOR.
COMP compares the content of two or two sets of files.
COMPACT Displays or changes the compression of files on NTFS partitions.
CONVERT Converts a FAT volume to NTFS. You cannot convert the current drive.
COPY Copies at least one file to another location.
DATE: displays or sets the DATE.
DEL deletes at least one file.
DIR Displays files and subdirectories in a directory.
DISKCOMP compares two floppy disks.
DISKCOPY copies the content of one floppy disk to another.
DOSKEY: edit the command line, call the Windows Command, and create a macro.
ECHO Displays the message, or explicitly opens or closes the command.
ENDLOCAL ends the localization of Environment Changes in the batch file.
ERASE deletes at least one file.
EXIT to EXIT the CMD. EXE program (command interpreter ).
FC compares two or two sets of files and displays the differences.
FIND searches for text strings in the file.
FINDSTR searches for strings in the file.
FOR runs a specified command FOR each file in a set of files.
FORMAT the disk for use with Windows.
FTYPE Displays or modifies the file type associated with the file extension.
GOTO points the Windows command interpreter to a specified line in the batch processing program.
GRAFTABL enables Windows to display extended character sets in image mode.
HELP provides HELP information for Windows commands.
IF executes conditional processing in the batch processing program.
LABEL to create, change, or delete the volume LABEL of a disk.
MD creates a directory.
Create a directory using MKDIR.
MODE: configure the system device.
MORE: display a result screen at a time.
MOVE Moves the file from one directory to another.
PATH: displays or sets the search PATH for executable files.
PAUSE Suspends processing of batch files and displays messages.
POPD restores the previous value of the current directory saved by PUSHD.
PRINT a text file.
PROMPT to change the Windows command PROMPT.
PUSHD saves the current directory and changes it.
RD deletes the directory.
RECOVER restores readable information from the faulty disk.
REM record comments in a batch file or CONFIG. SYS.
Rename the file.
RENAME the file.
REPLACE the file.
Delete the RMDIR directory.
SET displays, sets, or deletes Windows environment variables.
SETLOCAL starts localization of Environment Changes in the batch file.
SHIFT changes the positions of parameters that can be replaced in a batch file.
SORT classifies input.
START starts another window to run the specified program or command.
SUBST Associates the path with a drive letter.
TIME: displays or sets the system TIME.
TITLE: Set the TITLE of the CMD. EXE session.
TREE displays the directory structure of the drive or path in graphic mode.
TYPE: displays the content of a text file.
Server displays the Windows version.
Verify tells windows whether to verify that the file has been correctly written to the disk.
VOL Displays the volume label and serial number of the disk.
Xcopy copies the file and directory tree.

 


System (execute shell command)
Related functions fork, execve, waitpid, popen

Header file # include <stdlib. h>

Defines the INT system (const char * string) function );

Function Description: System () calls fork () to generate sub-processes. The sub-process calls/bin/sh-C string to execute the command represented by the string parameter, after the command is executed, the original called process is returned. The sigchld signal is temporarily shelved during system () calls, while the SIGINT and sigquit signals are ignored.

Return Value: If system () fails to call/bin/sh, 127 is returned, and-1 is returned for other causes of failure. If the string parameter is a null pointer, a non-zero value is returned. If system () is successfully called, the return value after the shell command is executed is returned. However, the returned value may also be 127 returned when system () fails to call/bin/sh, therefore, it is best to check errno again to confirm the execution is successful.

Note: Do not use system () when writing programs with SUID/SGID permissions. System () inherits environment variables, which may cause system security problems.

Example # include <stdlib. h>
Main ()
{
System ("LS-Al/etc/passwd/etc/shadow ");
}

Run-rw-r -- 1 root 705 Sep 3 13: 52/etc/passwd
-R --------- 1 root 572 Sep 2 15: 34/etc/shadow


**************************************** **************************************** **************

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.