Skip to content

Latest commit

 

History

History
115 lines (88 loc) · 4.22 KB

system-wsystem.md

File metadata and controls

115 lines (88 loc) · 4.22 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic apiname apilocation apitype f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
system, _wsystem | Microsoft Docs
11/04/2016
cpp-standard-libraries
article
system
_wsystem
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-runtime-l1-1-0.dll
DLLExport
_tsystem
_wsystem
C++
_wsystem function
wsystem function
tsystem function
_tsystem function
system function
commands, executing
command interpreter
7d3df2b6-f742-49ce-bf52-012b0aee3df5
17
corob-msft
corob
ghogen

system, _wsystem

Executes a command.

Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

Syntax

int system(  
   const char *command   
);  
int _wsystem(  
   const wchar_t *command   
);  

Parameters

command
The command to be executed.

Return Value

If command is NULL and the command interpreter is found, returns a nonzero value. If the command interpreter is not found, returns 0 and sets errno to ENOENT. If command is not NULL, system returns 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, and errno is set to one of the following values:

E2BIG
The argument list (which is system-dependent) is too big.

ENOENT
The command interpreter cannot be found.

ENOEXEC
The command-interpreter file cannot be executed because the format is not valid.

ENOMEM
Not enough memory is available to execute command; or available memory has been corrupted; or a non-valid block exists, which indicates that the process that's making the call was not allocated correctly.

See _doserrno, errno, _sys_errlist, and _sys_nerr for more information about these return codes.

Remarks

The system function passes command to the command interpreter, which executes the string as an operating-system command. system uses the COMSPEC and PATH environment variables to locate the command-interpreter file CMD.exe. If command is NULL, the function just checks whether the command interpreter exists.

You must explicitly flush—by using fflush or _flushall—or close any stream before you call system.

_wsystem is a wide-character version of system; the command argument to _wsystem is 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

Requirements

Routine Required header
system <process.h> or <stdlib.h>
_wsystem <process.h> or <stdlib.h> or <wchar.h>

For additional compatibility information, see Compatibility.

Example

This example uses system to TYPE a text file.

// crt_system.c  
  
#include <process.h>  
  
int main( void )  
{  
   system( "type crt_system.txt" );  
}  

Input: crt_system.txt

Line one.  
Line two.  

Output

Line one.  
Line two.  

See Also

Process and Environment Control
_exec, _wexec Functions
exit, _Exit, _exit
_flushall
_spawn, _wspawn Functions