WAD CMD incompatibility

May 20, 2008
474
2
TCC 28.01.14 x64 Windows 10 [Version 10.0.19042.1237]
TCC Build 14 Windows 10 Build 19042

In the Flutter language (Beautiful native apps in record time) install on Windows, there is a flutter.bat file that does not run in TCC, though it does run in CMD. The issue appears to be related to this syntax (from Command Redirection, Pipes - Windows CMD - SS64.com):
commandA || commandB Run commandA, if it fails then run commandB

The specific code in the batch file is this:
Code:
REM Test if Git is available on the Host
where /q git || ECHO Error: Unable to find git in your PATH. && EXIT /B 1

I do have git installed and can find it with the WHERE command (and WHICH). But, in TCC, the batch file just exits here. If I modify the file and put an ECHO after that line, it never reaches it. This makes me suspect the issue may be related to the double pipe on that line.

I do not see this syntax anywhere in the help. Is this supposed to be supported? Do I need to enable some specific option for it? I think I already have most of the CMD options enabled.

Thanks.
 

samintz

Scott Mintz
May 20, 2008
1,530
20
Solon, OH, USA
The || and && operators are in the Help under Conditional Commands.

If you separate two commands by && (AND), the second command will be executed only if the first command's exit code is 0.
If you separate two commands by || (OR), the second command will be executed only if the first command's exit code is non-zero.
 

samintz

Scott Mintz
May 20, 2008
1,530
20
Solon, OH, USA
The issue appears to be related to having both || and && on the same line.
Code:
$ where /q git || echo No go && echo uh oh
uh oh

$ where /q gitmo || echo No go && echo uh oh
No go
uh oh
 
May 20, 2008
11,788
118
Syracuse, NY, USA
Or put in some parentheses ...

where /q git || (ECHO Error: Unable to find git in your PATH. && EXIT /B 1)
 
May 20, 2008
474
2
Thanks for the reminders on 'help conditional'. WHERE does find git and return a non-zero.

Putting parens around the second pair of commands does work here, but exposes the next issue in a called batch file.
Code:
TCC: C:\flutter\bin\internal\shared.bat [35]  Unbalanced parentheses "& ( "

Line 35 is the second SET in this block:
Code:
WHERE /Q pwsh.exe && (
    SET powershell_executable=pwsh.exe
) || WHERE /Q PowerShell.exe && (
    SET powershell_executable=PowerShell.exe
) || (
    ECHO Error: PowerShell executable not found.                        1>&2
    ECHO        Either pwsh.exe or PowerShell.exe must be in your PATH. 1>&2
    EXIT 1
)
I guess I could add more pairs of parens around each pair of commands and nest the parens for doing that. But, as this batch file is provided as part of the Flutter install, I would prefer not to have to modify it and the other called batch files after each install/upgrade. I would need to weigh which nuisance is lesser, modification or just running CMD. Hopefully, enabling some other option will let it work without doing either.

It's a CMD bug; you can work around it in several ways or you can turn on the various CMD bug duplication options.
I have checked 'Duplicate CMD.EXE bugs' as well as 'CMD.EXE delayed expansion'. Are there other options I should enable?
 
May 20, 2008
474
2
Why not just run this bat file, or all your bat files, using CMD? Many of us do that. We run our btm files using TCC.
I very rarely start CMD and then only because something doesn't work as expected under TCC. I live in TCMD/TCC, regularly using aliases, functions, BTMs, etc. If I change that habit, it will likely be because I am running tmux/bash/zsh on Linux instead.
 
You can still live in TCmd/TCC, and still run a .bat file, that only works with cmd.exe
Code:
e:\utils>ver

TCC  28.01.14 x64   Windows 10 [Version 10.0.19043.1237]

e:\utils>cmd.exe /c ver

Microsoft Windows [Version 10.0.19043.1237]

e:\utils>

Just follow cmd.exe /c with the name of your .bat file.

After the .bat file has completed its run from cmd.exe, you are back in TCC.

Joe
 
I very rarely start CMD and then only because something doesn't work as expected under TCC. I live in TCMD/TCC, regularly using aliases, functions, BTMs, etc. If I change that habit, it will likely be because I am running tmux/bash/zsh on Linux instead.
That's the nice thing about TCmd/TCC, being able to run another shell to do something that cannot be done in TCC. Example;
Code:
e:\utils>ver

TCC  28.01.14 x64   Windows 10 [Version 10.0.19043.1237]

e:\utils>wsl bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

e:\utils>wsl ls test*.bat
test.bat  test2.bat  testhta.bat  testkeys.bat

e:\utils>

I have an TCC alias;
Code:
usd=wsl qalc %1 USD to CAD
...that allows me to find out how much an amount of US Dollars is worth in Canadian Dollars;
Code:
e:\utils>usd 1
1 * dollar = approx. CAD 1.2361662

Thus, I can run my Linux programs from TCmd/TCC whenever I need to.

Joe
 
May 20, 2008
474
2
Joe,
I sometimes do the cmd /c ... in my TCC. It partly depends on whether it'll need elevated permissions or not; I don't often elevate TCC. I have wsl also, but had not tried running that within TCC, especially using the aliases. That's cool. Thanks for the ideas.
 
When I run ELEVATED.BAT from an un-elevated TCC in Windows 10 as follows;
Code:
start /pgm "cmd.exe" /b /c elevated.bat
...it returns not elevated.

When I run ELEVATED.BAT from an un-elevated TCC in Windows 10 as follows;
Code:
start /elevated /pgm "cmd.exe" /b /c elevated.bat
...it returns elevated.
Code:
::Elevated.bat
@setlocal
@echo off
NET FILE 1>NUL 2>NUL
if %errorlevel%==0 (echo Elevated) else (echo Not Elevated)
endlocal
pause

Thus, you can run your cmd.exe, and your .bat file, elevated from an un-elevated TCC.

Note that when I tried;
Code:
start /b /pgm "cmd.exe" /b /c elevated.bat
...no new console was created, and output from ELEVATED.BAT could be viewed.

When I tried;
Code:
start /b /elevated /pgm "cmd.exe" /b /c elevated.bat
...a new console was created, and destroyed, thus no output from ELEVATED.BAT could be viewed.

Not sure why that is.

Joe
 
Last edited:
When you install Take Command, it asks you whether you want to associate TCC with bat files. Just say no. If CMD is associated with bat files, then when you run a bat file, CMD will handle it. Maybe you also need to use an executable extension to get this to work from TCC's command line.
 
Last edited:

Similar threads

Replies
0
Views
557