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

SignUp Now!

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

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.

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.
I use DO /P all the time.
do f in /p some_command (echo %f)

In the above example, %f represents an entire output line, not just a token like FOR.
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?

Not knowing the syntax for mediainfo.exe, I'd start here.

do a in /p mediainfo.exe --Output=Video;%%Duration/String%% %i (@set duration=%a)
Almost! Mediainfo.exe seems OK but wrapping it in DO has an anomaly.

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)

Here's a workaround. But why is it necessary?

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

do a in /p mediainfo.exe --Output=Video;%%%%Duration/String%%%% %i (@set duration=%a)

And here is how @EXECSTR works.

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.
set duration=%@execstr[MediaInfo.exe --OutPut=Video;%%%%Duration/String%%%% %i]
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.

Similar threads