3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/msvcrt/process/system.c
6 * PURPOSE: Excutes a shell command
7 * PROGRAMER: Boudewijn Dekker
21 int system(const char *command
)
23 char *szCmdLine
= NULL
;
24 char *szComSpec
= NULL
;
26 PROCESS_INFORMATION ProcessInformation
;
27 STARTUPINFOA StartupInfo
;
33 szComSpec
= getenv("COMSPEC");
35 // system should return 0 if command is null and the shell is found
37 if (command
== NULL
) {
38 if (szComSpec
== NULL
)
44 // should return 127 or 0 ( MS ) if the shell is not found
45 // __set_errno(ENOENT);
47 if (szComSpec
== NULL
)
49 szComSpec
= "cmd.exe";
52 /* split the path from shell command */
53 s
= max(strrchr(szComSpec
, '\\'), strrchr(szComSpec
, '/'));
59 szCmdLine
= malloc(strlen(s
) + 4 + strlen(command
) + 1);
60 if (szCmdLine
== NULL
)
67 s
= strrchr(szCmdLine
, '.');
70 strcat(szCmdLine
, " /C ");
71 strcat(szCmdLine
, command
);
73 //command file has invalid format ENOEXEC
75 memset (&StartupInfo
, 0, sizeof(StartupInfo
));
76 StartupInfo
.cb
= sizeof(StartupInfo
);
77 StartupInfo
.lpReserved
= NULL
;
78 StartupInfo
.dwFlags
= STARTF_USESHOWWINDOW
;
79 StartupInfo
.wShowWindow
= SW_SHOWDEFAULT
;
80 StartupInfo
.lpReserved2
= NULL
;
81 StartupInfo
.cbReserved2
= 0;
83 // According to ansi standards the new process should ignore SIGINT and SIGQUIT
84 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
85 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
88 //SIGCHILD should be blocked aswell
90 result
= CreateProcessA(szComSpec
,
95 CREATE_NEW_PROCESS_GROUP
,
104 _dosmaperr(GetLastError());
108 CloseHandle(ProcessInformation
.hThread
);
110 // system should wait untill the calling process is finished
111 _cwait(&nStatus
,(int)ProcessInformation
.hProcess
,0);
112 CloseHandle(ProcessInformation
.hProcess
);