[PATCH 4/4] [cmd] Ensure current directory saved during cmd /c

Ann and Jason Edmeades jason at edmeades.me.uk
Mon Oct 1 06:40:17 CDT 2012


The cmd /c processing was actioned before saving away the current
directory, resulting in endlocal failing for a batch program. This
highlights as a failure during cmd /c which does not occur if the
same batch program is run from a running cmd.exe

Note: No tests because once cmd.exe is running, the environment
is set up and spawning new cmd.exe processes just inherit the
environment.

[Fixes bug 22715]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121001/05d80a82/attachment.html>
-------------- next part --------------
From 890b35b0730fe58c6ee0f4387b4f49081643bc47 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Mon, 1 Oct 2012 00:12:59 +0100
Subject: [PATCH 4/4] [cmd] Ensure current directory saved during cmd /c

The cmd /c processing was actioned before saving away the current
directory, resulting in endlocal failing for a batch program. This
highlights as a failure during cmd /c which does not occur if the
same batch program is run from a running cmd.exe

Note: No tests because once cmd.exe is running, the environment
is set up and spawning new cmd.exe processes just inherit the
environment.

[Fixes bug 22715]
---
 programs/cmd/wcmdmain.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 82ec153..e0e7f00 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -2509,6 +2509,15 @@ int wmain (int argc, WCHAR *argvW[])
           WCMD_strip_quotes(cmd);
   }
 
+  /* Save cwd into appropriate env var (Must be before the /c processing */
+  GetCurrentDirectoryW(1024, string);
+  if (IsCharAlphaW(string[0]) && string[1] == ':') {
+    static const WCHAR fmt[] = {'=','%','c',':','\0'};
+    wsprintfW(envvar, fmt, string[0]);
+    SetEnvironmentVariableW(envvar, string);
+    WINE_TRACE("Set %s to %s\n", wine_dbgstr_w(envvar), wine_dbgstr_w(string));
+  }
+
   if (opt_c) {
       /* If we do a "cmd /c command", we don't want to allocate a new
        * console since the command returns immediately. Rather, we use
@@ -2602,15 +2611,6 @@ int wmain (int argc, WCHAR *argvW[])
 
   }
 
-  /* Save cwd into appropriate env var */
-  GetCurrentDirectoryW(1024, string);
-  if (IsCharAlphaW(string[0]) && string[1] == ':') {
-    static const WCHAR fmt[] = {'=','%','c',':','\0'};
-    wsprintfW(envvar, fmt, string[0]);
-    SetEnvironmentVariableW(envvar, string);
-    WINE_TRACE("Set %s to %s\n", wine_dbgstr_w(envvar), wine_dbgstr_w(string));
-  }
-
   if (opt_k) {
       /* Parse the command string, without reading any more input */
       WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE);
-- 
1.7.9.5


More information about the wine-patches mailing list