cmd.exe: Add support for %ERRORLEVEL% in both batch and cmd line.

This commit is contained in:
Jason Edmeades 2007-02-20 00:40:28 +00:00 committed by Alexandre Julliard
parent 3bdb64149b
commit 938719062d
2 changed files with 29 additions and 2 deletions

View File

@ -146,13 +146,21 @@ int i;
/* contents of fred, then the digit 1. Would need to remove */
/* ExpandEnvStrings to achieve this */
/* Replace use of %0...%9 */
/* Replace use of %0...%9 and errorlevel*/
p = cmd1;
while ((p = strchr(p, '%'))) {
i = *(p+1) - '0';
if (*(p+1) == '~') {
WCMD_HandleTildaModifiers(&p, NULL);
p++;
} else if (CompareString (LOCALE_USER_DEFAULT,
NORM_IGNORECASE | SORT_STRINGSORT,
(p+1), 11, "ERRORLEVEL%", -1) == 2) {
char output[10];
sprintf(output, "%d", errorlevel);
s = strdup (p+12);
strcpy (p, output);
strcat (p, s);
} else if ((i >= 0) && (i <= 9)) {
s = strdup (p+2);
t = WCMD_parameter (context -> command, i + context -> shift_count, NULL);

View File

@ -301,13 +301,32 @@ int main (int argc, char *argv[])
void WCMD_process_command (char *command)
{
char *cmd, *p;
char *cmd, *p, *s;
int status, i, len;
DWORD count, creationDisposition;
HANDLE h;
char *whichcmd;
SECURITY_ATTRIBUTES sa;
/*
* Replace errorlevel with current value (This shrinks in
* place and hence no need to reallocate the memory yet)
*/
p = command;
while ((p = strchr(p, '%'))) {
if (CompareString (LOCALE_USER_DEFAULT,
NORM_IGNORECASE | SORT_STRINGSORT,
(p+1), 11, "ERRORLEVEL%", -1) == 2) {
char output[10];
sprintf(output, "%d", errorlevel);
s = strdup (p+12);
strcpy (p, output);
strcat (p, s);
} else {
p++;
}
}
/*
* Expand up environment variables.
*/