https://bugs.winehq.org/show_bug.cgi?id=50132
Bug ID: 50132 Summary: Command line: Incorrect behaviors in FOR () and IF () blocks Product: Wine Version: 5.21 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: cmd Assignee: wine-bugs@winehq.org Reporter: Psycho-A@yandex.ru Distribution: ---
The native CMD.exe contains many syntax and other errors related to the FOR and IF commands processing inside of ()-blocks. This is very importans for apps that require complex batch scripts on run. Let's begin.
Case 1: ------- Different behavior when using brackets after "DO"
:: Returns ")" error: for %%a in (*.txt) do if #==# ( echo File: "%%~a" ) :: Works normal: for %%a in (*.txt) do (if #==# ( echo File: "%%~a" )) :: Works normal: for %%a in (*.txt) do if #==# echo File: "%%~a"
In Windows CMD all three results works the same (returns ECHO text).
Case 2: ------- Reading empty lines of text file if EOL=# specified
:: ECHO will return "" text here: for /f "usebackq eol=: tokens=1" %%a in ("File.txt") do ( echo "%%~a" )
Windows CMD skips empty lines anyway.
Case 3: ------- Error behavior if an empty line with Space ot Tab is defined in body
:: Will return ")" error: if #==# ( echo Some text
) :: Just will show ECHO text: if #==# ( echo Some text )
Case 4: ------- Not-expanding variables from parent cycle child one
:: Will show "%~m" in child cycles: for %%f in (*.txt) do ( echo In parent cycle: "%%~f" for %%x in ("%%~f") do ( echo In child cycle: "%%~x" ) ) :: Will seek in "%~f" dir instead of "Folder1": for %%f in ("Folder1") do ( for /r "%%~f" %%x in (*.txt) do ( echo "%%~x" ) )
Windows CMD expands "%%f" in any child cycle's place.
Case 5: ------- Error if no quotes in file/command condition
:: Returns "DO is not an application" error: for /f %%a in (File.txt) do ( echo "%%~a" ) :: Reads strings of File.txt: for /f "usebackq" %%a in ("File.txt") do ( echo "%%~a" )
Windows CMD reads file in both cases ("usebackq" uses to use quotes around filename). This error appears only when target file not found.
Case 6: ------- Using global ">" redirection after ()-body issue:
:: Will show ECHO text and create empty Test.bug if #==# ( echo Text 1... echo Text 2... )> "Test.bug" :: Will write Test.bug with echo text (normal case) if #==# ( echo Text 1...> "Test.bug" echo Text 2...> "Test.bug" )
Windows CMD does the same as second in both cases.
Case 7: ------- Incorrect IF() ELSE() processing if FOR() inside
:: Returns "ELSE is not an application" error: if #==# ( echo IF condition. for %%m in (*.txt) do ( echo FOR cycle. ) ) else ( echo ELSE condition. ) :: Works normally: if #==# ( echo IF condition. ) else ( echo ELSE condition. )
Also ELSE works normal when IF condition is NOT equal.
Case 8: ------- No processing file mask if it's quoted
:: Returns txt files that found: for %%f in (*.txt) do ( echo "%%~f" ) :: Returns nothing for %%f in ("*.txt") do (echo "%%~f") for %%f in ("Dir*.txt") do (echo "%%~f")
The same is if FOR with /R key is used.
For now that's all I found. Some of Wine 4.x bugs I knew seems to be fixed already.
https://bugs.winehq.org/show_bug.cgi?id=50132
Psycho-A Psycho-A@yandex.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |major
https://bugs.winehq.org/show_bug.cgi?id=50132
Vijay Kamuju infyquest@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |infyquest@gmail.com
--- Comment #1 from Vijay Kamuju infyquest@gmail.com --- Can you please re-test with latest wine as most of them should be fixed with cmd rewrite.
https://bugs.winehq.org/show_bug.cgi?id=50132
Eric Pouech eric.pouech@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |eric.pouech@gmail.com
--- Comment #2 from Eric Pouech eric.pouech@gmail.com --- didn't retest, but theoricaly, all except #2 should be fixed by now
https://bugs.winehq.org/show_bug.cgi?id=50132
Fabian Maurer dark.shadow4@web.de changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |dark.shadow4@web.de
--- Comment #3 from Fabian Maurer dark.shadow4@web.de --- Tested against win7 x64 cmd
Case 1: Works Case 2: Broken, for empty lines still outputs "" Case 3: Works Case 4: Broken, syntax errors on wine (Note: Comments break things on windows). Can't get second part working on windows, always outputs nothing Case 5: Works Case 6: Works Case 7: Works Case 8: Broken, second part outputs nothing
https://bugs.winehq.org/show_bug.cgi?id=50132
Fabian Maurer dark.shadow4@web.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW
--- Comment #4 from Fabian Maurer dark.shadow4@web.de --- Addition: Case 5 has the wrong error message if File doesn't exist: Windows: "The system cannot find the file File.txt." Wine: "File not found.
Failed to open 'File.txt'"
https://bugs.winehq.org/show_bug.cgi?id=50132
--- Comment #5 from Eric Pouech eric.pouech@gmail.com --- (In reply to Fabian Maurer from comment #3)
Tested against win7 x64 cmd
Case 1: Works Case 2: Broken, for empty lines still outputs "" Case 3: Works Case 4: Broken, syntax errors on wine (Note: Comments break things on windows). Can't get second part working on windows, always outputs nothing Case 5: Works Case 6: Works Case 7: Works Case 8: Broken, second part outputs nothing
Thanks for retesting. it looks like (for 5 and 8) that cmd doesn't support modifiers (%~) on loop variables. Added to my TODO list <g>