Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_system.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS system libraries 00004 * FILE: lib/msvcrt/process/system.c 00005 * PURPOSE: Excutes a shell command 00006 * PROGRAMER: Ariadne 00007 * UPDATE HISTORY: 00008 * 04/03/99: Created 00009 */ 00010 00011 #include <precomp.h> 00012 #include <stdlib.h> 00013 #include <string.h> 00014 #include <process.h> 00015 00016 00017 /* 00018 * @implemented 00019 */ 00020 int system(const char *command) 00021 { 00022 char *szCmdLine = NULL; 00023 char *szComSpec = NULL; 00024 00025 PROCESS_INFORMATION ProcessInformation; 00026 STARTUPINFOA StartupInfo; 00027 char *s; 00028 BOOL result; 00029 00030 int nStatus; 00031 00032 szComSpec = getenv("COMSPEC"); 00033 00034 // system should return 0 if command is null and the shell is found 00035 00036 if (command == NULL) { 00037 if (szComSpec == NULL) 00038 return 0; 00039 else 00040 return 1; 00041 } 00042 00043 if (szComSpec == NULL) 00044 return -1; 00045 00046 // should return 127 or 0 ( MS ) if the shell is not found 00047 // _set_errno(ENOENT); 00048 00049 if (szComSpec == NULL) 00050 { 00051 szComSpec = "cmd.exe"; 00052 } 00053 00054 /* split the path from shell command */ 00055 s = max(strrchr(szComSpec, '\\'), strrchr(szComSpec, '/')); 00056 if (s == NULL) 00057 s = szComSpec; 00058 else 00059 s++; 00060 00061 szCmdLine = malloc(strlen(s) + 4 + strlen(command) + 1); 00062 if (szCmdLine == NULL) 00063 { 00064 _set_errno(ENOMEM); 00065 return -1; 00066 } 00067 00068 strcpy(szCmdLine, s); 00069 s = strrchr(szCmdLine, '.'); 00070 if (s) 00071 *s = 0; 00072 strcat(szCmdLine, " /C "); 00073 strcat(szCmdLine, command); 00074 00075 //command file has invalid format ENOEXEC 00076 00077 memset (&StartupInfo, 0, sizeof(StartupInfo)); 00078 StartupInfo.cb = sizeof(StartupInfo); 00079 StartupInfo.lpReserved= NULL; 00080 StartupInfo.dwFlags = STARTF_USESHOWWINDOW; 00081 StartupInfo.wShowWindow = SW_SHOWDEFAULT; 00082 StartupInfo.lpReserved2 = NULL; 00083 StartupInfo.cbReserved2 = 0; 00084 00085 // According to ansi standards the new process should ignore SIGINT and SIGQUIT 00086 // In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP, 00087 // thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process. 00088 00089 00090 //SIGCHILD should be blocked aswell 00091 00092 result = CreateProcessA(szComSpec, 00093 szCmdLine, 00094 NULL, 00095 NULL, 00096 TRUE, 00097 CREATE_NEW_PROCESS_GROUP, 00098 NULL, 00099 NULL, 00100 &StartupInfo, 00101 &ProcessInformation); 00102 free(szCmdLine); 00103 00104 if (result == FALSE) 00105 { 00106 _dosmaperr(GetLastError()); 00107 return -1; 00108 } 00109 00110 CloseHandle(ProcessInformation.hThread); 00111 00112 // system should wait untill the calling process is finished 00113 _cwait(&nStatus,(intptr_t)ProcessInformation.hProcess,0); 00114 CloseHandle(ProcessInformation.hProcess); 00115 00116 return nStatus; 00117 } 00118 00119 int CDECL _wsystem(const wchar_t* cmd) 00120 { 00121 FIXME("_wsystem stub\n"); 00122 return -1; 00123 } Generated on Sat May 19 2012 04:34:36 for ReactOS by
1.7.6.1
|