Jason Edmeades : cmd: cmd.exe /c or / k should suppress copy overwrite prompts.

Alexandre Julliard julliard at winehq.org
Tue Oct 2 14:09:39 CDT 2012


Module: wine
Branch: master
Commit: b1dacc6c379ede878b5740a8ab5df635538b6e14
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b1dacc6c379ede878b5740a8ab5df635538b6e14

Author: Jason Edmeades <jason at edmeades.me.uk>
Date:   Mon Oct  1 22:37:17 2012 +0100

cmd: cmd.exe /c or /k should suppress copy overwrite prompts.

---

 programs/cmd/builtins.c                  |    3 +-
 programs/cmd/tests/test_builtins.cmd     |   86 ++++++++++++++++++++++++++++++
 programs/cmd/tests/test_builtins.cmd.exp |   43 +++++++++++++++
 programs/cmd/wcmdmain.c                  |    7 ++-
 4 files changed, 137 insertions(+), 2 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index f6922ad..f1c356c 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -36,6 +36,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(cmd);
 
 extern int defaultColor;
 extern BOOL echo_mode;
+extern BOOL interactive;
 
 struct env_stack *pushd_directories;
 const WCHAR dotW[]    = {'.','\0'};
@@ -446,7 +447,7 @@ void WCMD_copy (void) {
   else {
     /* By default, we will force the overwrite in batch mode and ask for
      * confirmation in interactive mode. */
-    force = !!context;
+    force = !interactive;
 
     /* If COPYCMD is set, then we force the overwrite with /Y and ask for
      * confirmation with /-Y. If COPYCMD is neither of those, then we use the
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index d89721a..1c0f875 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1816,8 +1816,94 @@ goto :eof
 :endlocalfinished
 echo %var%
 
+set var=
+set var2=
 cd .. & rd /q/s foobar
 
+echo ------------ cmd.exe command lines ------------
+mkdir foobar
+cd foobar
+echo file1 > file1
+
+rem Basic test of command line. Note a section prefix per command
+rem to resync, as wine does not output anything in these cases yet.
+echo --- Test 1
+cmd.exe /c echo Line1
+echo --- Test 2
+cmd.exe /c echo Test quotes "&" work
+echo --- Test 3
+cmd.exe /c echo "&"
+echo --- Test 4
+cmd.exe /c echo "<"
+echo --- Test 5
+cmd.exe /c echo ">"
+echo --- Test 6
+cmd.exe /c echo "\"
+echo --- Test 7
+cmd.exe /c echo "|"
+echo --- Test 8
+cmd.exe /c echo "`"
+echo --- Test 9
+cmd.exe /c echo """
+echo --- Test 10
+echo on > file3
+ at type file3
+ at echo off
+echo --- Test 11
+cmd.exe /c echo on >file3
+ at type file3
+ at echo off
+echo --- Test 12
+cmd.exe /c "echo passed1"
+echo --- Test 13
+cmd.exe /c " echo passed2 "
+echo --- Test 14
+cmd.exe /c "dir /ad ..\fooba* /b"
+echo --- Test 15
+
+rem Ensure no interactive prompting when cmd.exe /c or /k
+echo file2 > file2
+cmd.exe /c copy file1 file2 >nul
+echo No prompts or I would not get here1
+rem - Try cmd.exe /k as well
+cmd.exe /k "copy file1 file2 >nul && exit"
+echo No prompts or I would not get here2
+
+rem Non existing variable expansion is as per command line, ie left as-is
+cmd.exe /c echo %%hello1%%
+cmd.exe /c echo %%hello2
+cmd.exe /c echo %%hello3^:h=t%%
+cmd.exe /c echo %%hello4%%%%
+
+rem Cannot issue a call from cmd.exe /c
+cmd.exe /c call :hello5
+
+rem %1-9 has no meaning
+cmd.exe /c echo one = %%1
+
+rem for loop vars need expanding
+cmd.exe /c for /L %%i in (1,1,5) do @echo %%i
+
+rem goto's are ineffective
+cmd.exe /c goto :fred
+cmd.exe /c goto eof
+
+rem - %var% is expanded at read time, not execute time
+set var=11
+cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && echo var contents: %%var%%"
+
+rem - endlocal ineffective on cmd.exe /c lines
+cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && set var"
+set var=99
+
+rem - Environment is inherited ok
+cmd.exe /c ECHO %%VAR%%
+
+rem - Exit works
+cmd.exe /c exit
+
+cd ..
+rd foobar /s /q
 echo ------------ Testing Errorlevel ------------
 rem WARNING: Do *not* add tests using ErrorLevel after this section
 should_not_exist 2> nul > nul
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 4bab1ef..e817706 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -907,6 +907,49 @@ value1
 2
 1
 1
+------------ cmd.exe command lines ------------
+--- Test 1
+Line1
+--- Test 2
+ at todo_wine@Test quotes "&" work
+--- Test 3
+ at todo_wine@"&"
+--- Test 4
+ at todo_wine@"<"
+--- Test 5
+ at todo_wine@">"
+--- Test 6
+ at todo_wine@"\"
+--- Test 7
+ at todo_wine@"|"
+--- Test 8
+ at todo_wine@"`"
+--- Test 9
+ at todo_wine@"""
+--- Test 10
+--- Test 11
+--- Test 12
+ at todo_wine@passed1
+--- Test 13
+ at todo_wine@passed2 at space@
+--- Test 14
+ at todo_wine@foobar
+--- Test 15
+No prompts or I would not get here1
+No prompts or I would not get here2
+%hello1%
+%hello2
+%hello3:h=t%
+%hello4%%
+one = %1
+1
+2
+3
+4
+5
+ at todo_wine@var contents: 11
+var=33 at space@
+99
 ------------ Testing Errorlevel ------------
 9009
 1
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 02babea..0e7a197 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -39,6 +39,7 @@ extern struct env_stack *pushd_directories;
 BATCH_CONTEXT *context = NULL;
 DWORD errorlevel;
 WCHAR quals[MAX_PATH], param1[MAXSTRING], param2[MAXSTRING];
+BOOL  interactive;
 
 int defaultColor = 7;
 BOOL echo_mode = TRUE;
@@ -2366,6 +2367,9 @@ int wmain (int argc, WCHAR *argvW[])
     WCMD_echo(eoff);
   }
 
+  /* Until we start to read from the keyboard, stay as non-interactive */
+  interactive = FALSE;
+
   if (opt_c || opt_k) {
       int     len,qcount;
       WCHAR** arg;
@@ -2625,7 +2629,8 @@ int wmain (int argc, WCHAR *argvW[])
  */
 
   SetEnvironmentVariableW(promptW, defaultpromptW);
-  WCMD_version ();
+  interactive = TRUE;
+  if (!opt_k) WCMD_version ();
   while (TRUE) {
 
     /* Read until EOF (which for std input is never, but if redirect




More information about the wine-cvs mailing list