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>
19 int system(const char *command)
21 char szCmdLine[MAX_PATH];
25 PROCESS_INFORMATION ProcessInformation;
26 STARTUPINFOA StartupInfo;
30 szComSpec = getenv("COMSPEC");
32 // system should return 0 if command is null and the shell is found
34 if ( command == NULL ) {
35 if ( szComSpec == NULL )
43 // should return 127 or 0 ( MS ) if the shell is not found
44 // __set_errno(ENOENT);
46 if ( szComSpec == NULL )
47 szComSpec = "cmd.exe";
51 strcpy(szCmdLine," /C ");
53 strncat(szCmdLine,command,MAX_PATH-5);
55 //check for a too long argument E2BIG
57 //command file has invalid format ENOEXEC
60 StartupInfo.cb = sizeof(StartupInfo);
61 StartupInfo.lpReserved= NULL;
62 StartupInfo.dwFlags = 0;
63 StartupInfo.wShowWindow = SW_SHOWDEFAULT;
64 StartupInfo.lpReserved2 = NULL;
65 StartupInfo.cbReserved2 = 0;
67 // According to ansi standards the new process should ignore SIGINT and SIGQUIT
68 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
69 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
72 //SIGCHILD should be blocked aswell
74 if ( CreateProcessA(szComSpec,szCmdLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,NULL,&StartupInfo,&ProcessInformation) == FALSE) {
79 // system should wait untill the calling process is finished
81 _cwait(&nStatus,(int)ProcessInformation.hProcess,0);
83 // free the comspec [ if the COMSPEC == NULL provision is removed