Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

minor difference, cmd vs tcc

May
103
2
@echo off
::

FOR /F "usebackq tokens=3" %%i IN (`REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild 2^>nul`) DO SET /A "CurrentBuild=%%i"

echo CurrentBuild from registry is %CurrentBuild%
IF %CurrentBuild% GEQ 22000 (
echo yes, we are windows 11 based on CurrentBuild
)


============================

This works in cmd and TCC, but gives a spurious error or warning in TCC:
============================

d:\batch>winver2.bat
TCC: D:\batch\winver2.bat [4] No expression ""
CurrentBuild from registry is 22621
yes, we are windows 11 based on CurrentBuild

d:\batch>cmd /c winver2.bat
CurrentBuild from registry is 22621
yes, we are windows 11 based on CurrentBuild

===========================
What would I need to change to make it work without warnings in both CMD and TCC ?
 
I didn't find a simple answer, but the following workaround will suffice:
=====================================
@echo off
::

SET "usebackquotes=usebackq"
IF 01 == 1 (
SET "usebackquotes= "
)
FOR /F "%usebackquotes% tokens=3" %%i IN (`REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild 2^>nul`) DO SET /A "CurrentBuild=%%i"

echo CurrentBuild from registry is %CurrentBuild%
IF %CurrentBuild% GEQ 22000 (
echo yes, we are windows 11 based on CurrentBuild
)
 
Code:
    @echo off
    ::

    IF 01 == 1 (
    :: we're running TCC, use @regquery
        set /a CurrentBuild=%@regquery["HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentBuild"]
    ) else (
    :: we're running CMD, can't use @requery
        FOR /F "usebackq tokens=3" %%i IN ([ICODE]REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild 2^>nul[/ICODE]) DO SET /A "CurrentBuild=%%i"
    )
    echo CurrentBuild from registry is %CurrentBuild%
    IF %CurrentBuild% GEQ 22000 (
        echo yes, we are windows 11 based on CurrentBuild
    )
 
Simple solution is to not use TCC to run .bat/.cmd files. They are not compatible, and the more TCC or CMD features you explore, the less would they be.
 
Yes, but ... (There's always a but, isn't there?)

On my main PC, I mostly use TCC. So all batch type scripts can be / will be run under TCC. But I have a boatload of "tools" that I carry around on a flash drive, and I need those to work under CMD. So it's helpful to have a number of "tools" that can be run under either command interpreter.

Recently I've been getting a little more into Powershell. I don't care much for the syntax, but man it's powerful! And there I'm starting to encounter more and more differences between Powershell 5.1 (the default on most Windows 10 and Windows 11 computers) and Powershell 7.4. Life is never simple, is it?
 
I only make a BAT or CMD file to run with CMD as a comparison to TCC. The one exception is VCVARS64.BAT and I don't use that much since I wrote a BTM to update a DUMPBIN.EXE (which I use often) AppPaths entry when Visual C installs a new one and zaps the old one. I don't care to put "C:\program files\microsoft visual studio\2022\community\vc\tools\msvc\14.29.30133\bin\hostx64\x64\" in the path for the sake of one program. AppPaths works fine. I imagine a DUMPBIN.BTM stub would also work.
 
I actually don't have Visual-C installed at this moment. I have in the past, and man that is one big sucker, and it adds a bunch of junk to your path.

I have msys64 installed, with the Mingw c compiler, and Tiny-C, which I use for some small programs of my own.

For big complex batch files, written and distributed by others, I just use CMD. VCVARS64 would be one such tool, others would include W10UI (for integrating Windows updates), and the tools for creating an updated Win7 iso using the Simplix update pack. Others, whose efforts I do appreciate, have spent countless hours writing, debugging, and updating those tools.
 
@echo off
::

FOR /F "usebackq tokens=3" %%i IN (REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild 2^>nul) DO SET /A "CurrentBuild=%%i"

echo CurrentBuild from registry is %CurrentBuild%
IF %CurrentBuild% GEQ 22000 (
echo yes, we are windows 11 based on CurrentBuild
)


============================

This works in cmd and TCC, but gives a spurious error or warning in TCC:
============================

d:\batch>winver2.bat
TCC: D:\batch\winver2.bat [4] No expression ""
CurrentBuild from registry is 22621
yes, we are windows 11 based on CurrentBuild

d:\batch>cmd /c winver2.bat
CurrentBuild from registry is 22621
yes, we are windows 11 based on CurrentBuild

===========================
What would I need to change to make it work without warnings in both CMD and TCC ?

It is a real error, not a spurious error. TCC is flagging the errorr, and CMD is ignoring it.

The problem is with the SET /A ... command. Because you're passing multiple lines that don't all have an argument #3, you end up with this line:

Code:
set /a CurrentBuild=

Since you asked for numeric evaluation but failed to provide a numeric expression, TCC displays an error message. CMD silently fails.

The simple workaround in this instance is to remove the /A option, which is meaningless when you do not have an expression you need to expand and evaluate.
 
It is a real error, not a spurious error. TCC is flagging the errorr, and CMD is ignoring it.

The problem is with the SET /A ... command. Because you're passing multiple lines that don't all have an argument #3, you end up with this line:

Code:
set /a CurrentBuild=

Since you asked for numeric evaluation but failed to provide a numeric expression, TCC displays an error message. CMD silently fails.

The simple workaround in this instance is to remove the /A option, which is meaningless when you do not have an expression you need to expand and evaluate.
Ahhhh.... I missed that one completely. Thanks for pointing it out.
 
Back
Top