2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/crtdll/process/system.c
5 * PURPOSE: Excutes a shell command
6 * PROGRAMER: Boudewijn Dekker
11 #include <crtdll/stdlib.h>
12 #include <crtdll/string.h>
13 #include <crtdll/process.h>
15 int system(const char *command)
17 char szCmdLine[MAX_PATH];
21 PROCESS_INFORMATION ProcessInformation;
22 STARTUPINFO StartupInfo;
26 szComSpec = getenv("COMSPEC");
28 // system should return 0 if command is null and the shell is found
30 if ( command == NULL ) {
31 if ( szComSpec == NULL )
39 // should return 127 or 0 ( MS ) if the shell is not found
40 // __set_errno(ENOENT);
42 if ( szComSpec == NULL )
43 szComSpec = "cmd.exe";
47 strcpy(szCmdLine," /C ");
49 strncat(szCmdLine,command,MAX_PATH-5);
51 //check for a too long argument E2BIG
53 //command file has invalid format ENOEXEC
56 StartupInfo.cb = sizeof(STARTUPINFO);
57 StartupInfo.lpReserved= NULL;
58 StartupInfo.dwFlags = 0;
59 StartupInfo.wShowWindow = SW_SHOWDEFAULT;
60 StartupInfo.lpReserved2 = NULL;
61 StartupInfo.cbReserved2 = 0;
63 // According to ansi standards the new process should ignore SIGINT and SIGQUIT
64 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
65 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
68 //SIGCHILD should be blocked aswell
70 if ( CreateProcessA(szComSpec,szCmdLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,NULL,&StartupInfo,&ProcessInformation) == FALSE) {
75 // system should wait untill the calling process is finished
77 _cwait(&nStatus,(int)ProcessInformation.hProcess,0);
79 // free the comspec [ if the COMSPEC == NULL provision is removed