[PATCH 2 6/7] programs/cmd: expand commandline before parsing it (interactive mode)
Eric Pouech
eric.pouech at gmail.com
Wed Feb 2 11:39:00 CST 2022
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52344
Signed-off-by: Eric Pouech <eric.pouech at gmail.com>
---
programs/cmd/tests/interactive_builtins.cmd | 3 +++
programs/cmd/tests/interactive_builtins.cmd.exp | 5 +++++
programs/cmd/wcmdmain.c | 10 +++++-----
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/programs/cmd/tests/interactive_builtins.cmd b/programs/cmd/tests/interactive_builtins.cmd
index 1a06c29d103..96d53f371fd 100644
--- a/programs/cmd/tests/interactive_builtins.cmd
+++ b/programs/cmd/tests/interactive_builtins.cmd
@@ -28,6 +28,9 @@ if exist c:\windows (
@if exist c:\windows (
@echo bar
)
+echo --------- testing expansion for variables
+set myownecho=echo
+%myownecho% foo
echo --------- testing syntax errors
if exist c:\windows (
echo bar
diff --git a/programs/cmd/tests/interactive_builtins.cmd.exp b/programs/cmd/tests/interactive_builtins.cmd.exp
index 331e9b54b38..81114ccbd86 100644
--- a/programs/cmd/tests/interactive_builtins.cmd.exp
+++ b/programs/cmd/tests/interactive_builtins.cmd.exp
@@ -48,6 +48,11 @@ bar
@more@ @echo bar
@more@)
bar
+echo --------- testing expansion for variables
+--------- testing expansion for variables
+set myownecho=echo
+%myownecho% foo
+foo
echo --------- testing syntax errors
--------- testing syntax errors
if exist c:\windows (
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index bfd72953639..b79c9361fc1 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1309,6 +1309,11 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
new_redir = heap_xalloc(MAXSTRING * sizeof(WCHAR));
redir = new_redir;
+ /* Expand variables in command line mode only (batch mode will
+ be expanded as the line is read in, except for 'for' loops) */
+ handleExpansion(new_cmd, (context != NULL), delayedsubst);
+ handleExpansion(new_redir, (context != NULL), delayedsubst);
+
/* Strip leading whitespaces, and a '@' if supplied */
whichcmd = WCMD_skip_leading_spaces(cmd);
WINE_TRACE("Command: '%s'\n", wine_dbgstr_w(cmd));
@@ -1359,11 +1364,6 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
lstrcpyW(new_redir, redirects);
}
- /* Expand variables in command line mode only (batch mode will
- be expanded as the line is read in, except for 'for' loops) */
- handleExpansion(new_cmd, (context != NULL), delayedsubst);
- handleExpansion(new_redir, (context != NULL), delayedsubst);
-
/*
* Changing default drive has to be handled as a special case, anything
* else if it exists after whitespace is ignored
More information about the wine-devel
mailing list