FOR usage error from TCC but not from CMD

Oct 24, 2018
15
0
I'm having a hard time figuring out why TCC is not accepting a FOR command that CMD is accepting and working as expected.

I am trying to use WMIC to get the version of a file. The following works when run with CMD.

Code:
FOR /F "tokens=2 delims==" %%I IN ('wmic datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get version /format:list') DO SET "RESULT=%%I"

ECHO %RESULT%

When this is run with TCC I get this:

Code:
test.cmd [10]  Usage : FOR [/A:[[-][+]rhsdaecjot] /D /F ["options"] /H /I"text" /L /Nj /O:[-]adegnrstu /R [path] /T"..." /W] %var IN ([@]set | start, step, end) [DO] command ...

I am not understanding what the issue is and would appreciate any help.
 
Oct 24, 2018
15
0
I think this has something to do with the single quotes around the wmic command. When this is removed CMD will fail with The system cannot find the file wmic.

I just cannot figure out how TCC wants this formated.
 
Oct 24, 2018
15
0
I think I figured out how to work around this.

Code:
wmic datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get version /format:list | for /f "tokens=2 delims==" %%I in (@CON:) DO ECHO %%I
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,446
88
Albuquerque, NM
prospero.unm.edu
Can't help you with FOR -- but when I want to snarf the output of a command, I use %@EXECSTR. (If the object of the game is to get the file's version number, it might be a lot easier to use %@FILEVER instead of calling an external.)
 
Oct 24, 2018
15
0
I really appreciate the help.

%@EXECSTR gives me "ECHO is OFF" which is common with wmic because of all of the garbage that it spits out.
I cannot find %@FILEVER in the help file, only %@VERINFO. This may work however, I need to run this on a remote system. I am checking the version of a program as part of an upgrade script. I just figured it would be easier to provide a local file check as an example.

Is there a way to direct TCC to execute the FOR command in "CMD mode" then switch back to TCC mode?

To add to the confusion, this gives me nothing:
WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value /format:csv | for /f "skip=2 tokens=2 delims=," %a in (@CON:) do (set VER=%a)

While this gives me the version of the file:
WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value /format:csv | for /f "skip=2 tokens=2 delims=," %a in (@CON:) do (ECHO %a)

Why can't I just assign the value to a variable? sigh
 
Hi @rmoody ,

Try this;
Code:
c:\users\jlc\utils>echo %@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]
Version=7.6.4.0

To assign the value to a variable;
Code:
c:\users\jlc\utils>set theVersion=%@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]

c:\users\jlc\utils>echo %theVersion
Version=7.6.4.0

c:\program files\notepad++>echo %@word["=",-0,%theVersion]
7.6.4.0

Joe
 
Last edited:
May 20, 2008
11,380
98
Syracuse, NY, USA
Must you use FOR? In TCC you can ...

Code:
v:\> set notepad_version=%@wmi[root\cimv2,"select version from CIM_datafile where name='c:\\windows\\system32\\notepad.exe'"]

v:\> echo %notepad_version
6.1.7600.16385
 
Oct 24, 2018
15
0
Hi @rmoody ,

Try this;
Code:
c:\users\jlc\utils>echo %@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]
Version=7.6.4.0

To assign the value to a variable;
Code:
c:\users\jlc\utils>set theVersion=%@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]

c:\users\jlc\utils>echo %theVersion
Version=7.6.4.0

c:\program files\notepad++>echo %@word["=",-0,%theVersion]
7.6.4.0

Joe

Thank you! This seems to work! Tested on a remote system like this:

set theVersion=%@execstr[2,WMIC /NODE:"systemname" datafile where "name='C:\\Program Files (x86)\\Notepad++\\notepad++.exe'" get Version /value]

I'm in no way attached to a FOR loop, it's just what I had found. I'll use whatever works, I'm all about the Perl moto: There's more than one way to do it.

vefatica: I could not figure out how to use @VERINFO to get the version of a file on a remote system.
 
May 20, 2008
11,380
98
Syracuse, NY, USA
vefatica: I could not figure out how to use @VERINFO to get the version of a file on a remote system.
This works.
Code:
v:\> echo %@verinfo[\\zz\c$\Windows\System32\notepad.exe]
6.1.7600.16385 (win7_rtm.090713-1255)
I'm pretty sure it will not work with a URL.
 
May 20, 2008
11,380
98
Syracuse, NY, USA
For what it's worth, WMI is pretty easy to use remotely (if the firewall allows it). Below, the only difference is the addition of "\\bb\" to the namespace parameter
Code:
v:\> echo %@wmi[root\cimv2,"select version from CIM_datafile where name='c:\\windows\\system32\\notepad.exe'"]
6.1.7600.16385

v:\> echo %@wmi[\\bb\root\cimv2,"select version from CIM_datafile where name='c:\\windows\\system32\\notepad.exe'"]
10.0.18362.1
 
  • Like
Reactions: rmoody
Oct 24, 2018
15
0
Just updated TCC and tested. The FOR command I was having issues with works now.

Thank you so much for fixing that and for such a great product (been using TCC off and on since the WFWG 3.11 days!)
 
Similar threads
Thread starter Title Forum Replies Date
G High CPU usage Support 27
C Control Everything CPU usage at startup? Support 7
Joe Caverly START Dialog usage of %_ variables Support 0
Gorlash usage rules ?? Support 2
T bdebugger / ide usage confusion Support 14
A pdir function usage Support 3
B Disk usage and hard links Support 16
C CPU Usage Support 12
epement Youtube videos on Take Command usage Support 4
M CPU Usage Support 28
JohnQSmith RD / RMDIR Usage Support 5
JohnQSmith RECYCLE usage? Support 1
vefatica IDE balloon usage tips Support 4
Juanma Barranquero CPU Usage after suspend Support 5
E CPU usage of a process Support 2
C Copy (sys) error Support 3
T Error: This page can’t be displayed Make sure the web address //ieframe.dll/dnserrordiagoff.htm# is correct. Support 8
kb6ojs How to? "Specified Account Already Exists" error installing TCMD v27 Support 12
samintz How to? Abort on error DO loop Support 10
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica ON ERROR terminates DO loop. Support 0
C Google intregration error Support 4
C FB intregration error Support 0
gworley rd (Remove Directory) gives interesting error: Support 2
D How to? Skip removing directory (RMDIR) without error message Support 2
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
M Strange error messages from TCC in FTP copy Support 7
vefatica Error message from TOUCH Support 2
R FIND command error Support 9
fpefpe Python dll error Support 3
D error in help documentation? Support 0
K_Meinhard Help file error Support 1
X small translation error. Support 0
W pdir returns diff results between tcc and tcmd - one is an error msg Support 5
Dmitry L. Kobyakov From old version: had the setup's error been corrected? Support 6
vefatica Why no error message? Support 2
vefatica ON ERROR and pipes? Support 8
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
Joe Caverly TASKDIALOG Help link error Support 1
J Error "Contents lost before copy" Support 3
vefatica What's causing this error? Support 4
vefatica Error 203? Support 4
C Activation Error. Support 2
J Error running Python at command line Support 9
Joe Caverly PSHELL Error? Support 16
M Fixed PSHELL command returns error Support 2
vefatica REGDIR, strange error message Support 7
O Error in plugin /u Support 2
O TPIPE: Error -Can´t access textpipeengine.dll Support 24
fpefpe How to? script error Support 1

Similar threads