Fixed the FIXME in process.c/system to allow for system calls to be xecuted via the COMSPEC interpreter License: LGPL Changelog: * dlls/msvcrt/process.c: Jaco Greeff <jaco@puxedo.org> - Updated the system call to launch system commands via COMSPEC
diff -aurN msvcrt-B05/dlls/msvcrt/process.c msvcrt-B06/dlls/msvcrt/process.c --- msvcrt-B05/dlls/msvcrt/process.c Fri Oct 4 02:27:10 2002 +++ msvcrt-B06/dlls/msvcrt/process.c Tue Nov 5 13:04:49 2002 @@ -1,10 +1,11 @@ -/* + /* * msvcrt.dll spawn/exec functions * * Copyright 1996,1998 Marcus Meissner * Copyright 1996 Jukka Iivonen * Copyright 1997,2000 Uwe Bonnes * Copyright 2000 Jon Griffiths + * Copyright 2002 Jaco Greeff * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +29,7 @@ #include "config.h" #include <stdarg.h> +#include <stdio.h> #include "msvcrt.h" #include "msvcrt/errno.h" @@ -437,12 +439,34 @@ */ int MSVCRT_system(const char* cmd) { + static const char szExec[] = " /c "; + char szComspec[1024+1]; char* cmdcopy; int res; - /* Make a writable copy for CreateProcess */ - cmdcopy=_strdup(cmd); - /* FIXME: should probably launch cmd interpreter in COMSPEC */ + TRACE("(cmd == %s)\n", cmd); + + /* Get the value of COMSPEC which should point to our + * default command interpreter. If the interpreter is + * not available, fail. + */ + if (!GetEnvironmentVariableA("COMSPEC", szComspec, 1024)) + { + TRACE("COMSPEC not available, _system call fails\n"); + return -1; + } + + /* Allocate enough memory to hold the interpreter + command + * string and set it. When using the command interpreter in + * this way, it is executed as "comspec /c command" + */ + if (!(cmdcopy = (char *)MSVCRT_malloc(strlen(szComspec)+strlen(szExec)+strlen(cmd)+1))) + { + TRACE("Unable to allocate memory for _system call\n"); + return -1; + } + sprintf(cmdcopy, "%s%s%s", szComspec, szExec, cmd); + res=msvcrt_spawn(_P_WAIT, NULL, cmdcopy, NULL); MSVCRT_free(cmdcopy); return res;