2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/sdk/crt/process/_system.c
5 * PURPOSE: Excutes a shell command
20 int system(const char *command
)
22 char *szCmdLine
= NULL
;
23 char *szComSpec
= NULL
;
25 PROCESS_INFORMATION ProcessInformation
;
26 STARTUPINFOA StartupInfo
;
32 szComSpec
= getenv("COMSPEC");
34 // system should return 0 if command is null and the shell is found
36 if (command
== NULL
) {
37 if (szComSpec
== NULL
)
43 if (szComSpec
== NULL
)
46 // should return 127 or 0 ( MS ) if the shell is not found
47 // _set_errno(ENOENT);
49 if (szComSpec
== NULL
)
51 szComSpec
= "cmd.exe";
54 /* split the path from shell command */
55 s
= max(strrchr(szComSpec
, '\\'), strrchr(szComSpec
, '/'));
61 szCmdLine
= malloc(strlen(s
) + 4 + strlen(command
) + 1);
62 if (szCmdLine
== NULL
)
69 s
= strrchr(szCmdLine
, '.');
72 strcat(szCmdLine
, " /C ");
73 strcat(szCmdLine
, command
);
75 //command file has invalid format ENOEXEC
77 memset (&StartupInfo
, 0, sizeof(StartupInfo
));
78 StartupInfo
.cb
= sizeof(StartupInfo
);
79 StartupInfo
.lpReserved
= NULL
;
80 StartupInfo
.dwFlags
= STARTF_USESHOWWINDOW
;
81 StartupInfo
.wShowWindow
= SW_SHOWDEFAULT
;
82 StartupInfo
.lpReserved2
= NULL
;
83 StartupInfo
.cbReserved2
= 0;
85 // According to ansi standards the new process should ignore SIGINT and SIGQUIT
86 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
87 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
90 //SIGCHILD should be blocked aswell
92 result
= CreateProcessA(szComSpec
,
97 CREATE_NEW_PROCESS_GROUP
,
101 &ProcessInformation
);
106 _dosmaperr(GetLastError());
110 CloseHandle(ProcessInformation
.hThread
);
112 // system should wait untill the calling process is finished
113 _cwait(&nStatus
,(intptr_t)ProcessInformation
.hProcess
,0);
114 CloseHandle(ProcessInformation
.hProcess
);
119 int CDECL
_wsystem(const wchar_t* cmd
)
121 FIXME("_wsystem stub\n");