TCC has much more elegant ways for usebackq. What ways?

Oct 20, 2017
24
0
Netherlands
Take Command / TCC Help v.24 page 410:
"usebackq : Duplicates the awkward CMD syntax. A back quoted string is executed as a command;
a single quoted string is a literal string; and double quotes quote filenames in the file set. We don't
recommend usebackq for batch files written for TCC, as TCC has much more elegant ways of doing
the same things."

I’m looking in the wrong places and I can't find "much more elegant ways".
Please, give me direction or examples.

Thanks
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,923
51
Albuquerque, NM
prospero.unm.edu
Also: If you only want one line of a command's output, the @EXECSTR function is the neat way. If you want to process all lines of a command's output, you can pipe to a subroutine or an alias.
 

samintz

Scott Mintz
May 20, 2008
1,355
12
Solon, OH, USA
I use DO /P all the time.
Code:
do f in /p some_command (echo %f)
In the above example, %f represents an entire output line, not just a token like FOR.
 
Oct 20, 2017
24
0
Netherlands
Hi Charles & Scott,

I use this working line of code :

"for /f "delims=" "usebackq" %a in (`MediaInfo.exe --Output=Video;%%Duration/String%% "%i"`) do @set duration=%a"

The variable "duration" contains one line of output from the external programm MEDIAINFO.EXE.

How should this line of code work with @EXECSTR or DO /P?

Thanks
 
May 20, 2008
9,708
67
Syracuse, NY, USA
Not knowing the syntax for mediainfo.exe, I'd start here.

Code:
do a in /p mediainfo.exe --Output=Video;%%Duration/String%% %i (@set duration=%a)
 
May 20, 2008
9,708
67
Syracuse, NY, USA
Almost! Mediainfo.exe seems OK but wrapping it in DO has an anomaly.

Code:
v:\> MediaInfo.exe --OutPut=Video;%%Duration/String%% FlickAnimation.avi
3 s 933 ms

v:\> do a in /p MediaInfo.exe --OutPut=Video;%%Duration/String%% FlickAnimation.avi (echo %a)
/String
Here's a workaround. But why is it necessary?

Code:
v:\> do a in /p MediaInfo.exe --OutPut=Video;%%%%Duration/String%%%% FlickAnimation.avi (echo %a)
3 s 933 ms
For dumbenis, change my suggestion to

Code:
do a in /p mediainfo.exe --Output=Video;%%%%Duration/String%%%% %i (@set duration=%a)
And here is how @EXECSTR works.

Code:
v:\> set duration=%@execstr[MediaInfo.exe --OutPut=Video;%%%%Duration/String%%%% FlickAnimation.avi]

v:\> echo %duration
3 s 933 ms
So, dumbenis, instead of a FOR loop or DO loop you could do this.
Code:
set duration=%@execstr[MediaInfo.exe --OutPut=Video;%%%%Duration/String%%%% %i]
 

samintz

Scott Mintz
May 20, 2008
1,355
12
Solon, OH, USA
Commands that require percents are always going to be problematic to the parser. In the simplest case they can be doubled or escaped. But nested commands go through the parser more than once and might require multiple doublings.