Page 1 of 1

optional debug method

Posted: 25 Mar 2022 06:02
by lazna
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?

Re: optional debug method

Posted: 26 Mar 2022 04:56
by aGerman
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

Re: optional debug method

Posted: 26 Mar 2022 15:02
by lazna
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.

Re: optional debug method

Posted: 26 Mar 2022 15:16
by aGerman
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