optional debug method

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lazna
Posts: 53
Joined: 27 Dec 2012 10:54

optional debug method

#1 Post by lazna » 25 Mar 2022 06:02

Have large redistributional (zipfile with .cmd file and few bundled console utilities) batch script, where many times commands are processed in FOR loop with its output parsing. Informations readed by command are often HW (drivers) based so output may vary case by case unpredictible.

Thinking about to offer some optional debug method for script users which duplicate command output to STDOUT and debug file by (bundled) tee utility.
Thinking about something like this:

Code: Select all

if %1 == -d set "tee=^| utils\tee.exe debug.txt"
and to script loops append %tee%

Code: Select all

for /f %a in ('command1 par1 par2 ^| command2 par1 par2 %tee%') do something
is this suitable way to process for loop output AND copy its output to file? Aby better solution?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: optional debug method

#2 Post by aGerman » 26 Mar 2022 04:56

What you're doing using TEE is capturing the raw output of the pipe chain. You can't trace the tokenizing performed by FOR /F. E.g. you didn't specify any options in your example and thus, the default behavior is:
eol is semicolon
skip is 0
delims is space and tab
tokens is 1
usebackq is not defined
So, if you capture something like ";foo bar" the FOR loop will ignore it (what you have to keep in mind while observing your debug.txt). And if you capture "foo bar", only "foo" is assigned to %a which is not clear if you only read debug.txt.

Steffen

lazna
Posts: 53
Joined: 27 Dec 2012 10:54

Re: optional debug method

#3 Post by lazna » 26 Mar 2022 15:02

thanks for reply.

I do not specify any parsing options because this should be only example how I plane to employ tee command.

Raw commandchain output is exactly what I need, because it provide me possibility to perform tests on captured sample, and possibly improove parsing in next version.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: optional debug method

#4 Post by aGerman » 26 Mar 2022 15:16

I do not specify any parsing options because this should be only example
Of course. My list of defaults was just an emphasis of the things you need to know and have to keep in mind in this case.
Raw commandchain output is exactly what I need
Well, then TEE should be suitable for your needs I guess.

Steffen

Post Reply