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
13 #include <msvcrt/stdlib.h>
14 #include <msvcrt/string.h>
15 #include <msvcrt/process.h>
20 int system(const char *command
)
22 char szCmdLine
[MAX_PATH
];
26 PROCESS_INFORMATION ProcessInformation
;
27 STARTUPINFOA StartupInfo
;
31 szComSpec
= getenv("COMSPEC");
33 // system should return 0 if command is null and the shell is found
35 if ( command
== NULL
) {
36 if ( szComSpec
== NULL
)
44 // should return 127 or 0 ( MS ) if the shell is not found
45 // __set_errno(ENOENT);
47 if ( szComSpec
== NULL
)
48 szComSpec
= "cmd.exe";
52 strcpy(szCmdLine
," /C ");
54 strncat(szCmdLine
,command
,MAX_PATH
-5);
56 //check for a too long argument E2BIG
58 //command file has invalid format ENOEXEC
61 StartupInfo
.cb
= sizeof(StartupInfo
);
62 StartupInfo
.lpReserved
= NULL
;
63 StartupInfo
.dwFlags
= 0;
64 StartupInfo
.wShowWindow
= SW_SHOWDEFAULT
;
65 StartupInfo
.lpReserved2
= NULL
;
66 StartupInfo
.cbReserved2
= 0;
68 // According to ansi standards the new process should ignore SIGINT and SIGQUIT
69 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
70 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
73 //SIGCHILD should be blocked aswell
75 if ( CreateProcessA(szComSpec
,szCmdLine
,NULL
,NULL
,TRUE
,CREATE_NEW_PROCESS_GROUP
,NULL
,NULL
,&StartupInfo
,&ProcessInformation
) == FALSE
) {
80 // system should wait untill the calling process is finished
82 _cwait(&nStatus
,(int)ProcessInformation
.hProcess
,0);
84 // free the comspec [ if the COMSPEC == NULL provision is removed