Welcome!

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

SignUp Now!

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

Oct
31
0
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
 
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.
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.
 
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
 
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)
 
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]
 
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

Back
Top