3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/crtdll/process/system.c
6 * PURPOSE: Excutes a shell command
7 * PROGRAMER: Boudewijn Dekker
12 #include <msvcrt/stdlib.h>
13 #include <msvcrt/string.h>
14 #include <msvcrt/process.h>
16 int system(const char *command)
18 char szCmdLine[MAX_PATH];
22 PROCESS_INFORMATION ProcessInformation;
23 STARTUPINFO StartupInfo;
27 szComSpec = getenv("COMSPEC");
29 // system should return 0 if command is null and the shell is found
31 if ( command == NULL ) {
32 if ( szComSpec == NULL )
40 // should return 127 or 0 ( MS ) if the shell is not found
41 // __set_errno(ENOENT);
43 if ( szComSpec == NULL )
44 szComSpec = "cmd.exe";
48 strcpy(szCmdLine," /C ");
50 strncat(szCmdLine,command,MAX_PATH-5);
52 //check for a too long argument E2BIG
54 //command file has invalid format ENOEXEC
57 StartupInfo.cb = sizeof(STARTUPINFO);
58 StartupInfo.lpReserved= NULL;
59 StartupInfo.dwFlags = 0;
60 StartupInfo.wShowWindow = SW_SHOWDEFAULT;
61 StartupInfo.lpReserved2 = NULL;
62 StartupInfo.cbReserved2 = 0;
64 // According to ansi standards the new process should ignore SIGINT and SIGQUIT
65 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
66 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
69 //SIGCHILD should be blocked aswell
71 if ( CreateProcessA(szComSpec,szCmdLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,NULL,&StartupInfo,&ProcessInformation) == FALSE) {
76 // system should wait untill the calling process is finished
78 _cwait(&nStatus,(int)ProcessInformation.hProcess,0);
80 // free the comspec [ if the COMSPEC == NULL provision is removed