Welcome!

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

SignUp Now!

Surprises with redriections

Sep
134
1
I have created a script to practice with CLIP: and redirects and array.
For this I used the output of "?" to create a short help list for me :smile:.
The script uses the Screen statement instead the Echo command.
Code:
Setlocal
Unalias *
Unfunction *
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Set ArrName=arCommandsList
Set FirstLine=0
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:FillSharesArray_Sub
:: Working with the Clipboard
Set z=0
Set arIndex=0
:: Get the complete commandset in the Clipboard
  ? >CLIP:
:: Count lines to get the Arraysize
  Do FOREVER
    If "%@CLIP[%z%]" EQ "**EOC**" LEAVE
      Set z=%@INC[%z%]
      Set arIndex=%@INC[%arindex%]
  EndDo
::
  UnsetArray /Q %arrname
  SetArray /F %arrname[%arIndex%]
:: Now fill the Array
  Set z=%FirstLine%
  Set arIndex=0
  Do FOREVER
    If "%@CLIP[%z%]" EQ "**EOC**" LEAVE
      Set z=%@INC[%z%]
        Set %arrname[%arindex%]=%@CLIP[%@DEC[%z%]]
        Set arIndex=%@INC[%arindex%]
  EndDo
  Echo %@DEC[%@ARRAYINFO[%arrname,1]] lines in the Array
::
:: Scan the array
OPTION //UTF8=YES
Set tmpFN=%@UNIQUE[]
  Do z=0 To %@DEC[%@ARRAYINFO[%arrname,1]]
        Set Zeile=%@CLIP[%z%]
    Do Cmd In /L %zeile
:: Excludings ...
      If "%cmd%" EQ "?" ITERATE
:: Some Outputs in combination with Echo %cmd% can lead
:: to unwanted commands, e.g. Echo ON
:: so I use Screen instead
      Screen %_row %_column %cmd% ^r^n >>%tmpfn%
:: get the help, if any
      %cmd% /? >>%tmpfn%
      Echo %@REPEAT[=,%@DEC[%_COLUMNS]] >>%tmpfn
    EndDo
  EndDo
  List %tmpfn%
Erase %tmpfn%
Quit
It was a little surprise, that some commands would not be captured, e.g. BDEBUGGER, CASE etc.
But another effect was really curious:
If it comes to the keyword BDEBUGGER, the line
%cmd% /? >>%tmpfn%
has create a file named %tmpfn% and redirected the desired output to it !
Really, percentsigntmpfnpercentsign !
What is happend here ?
As a workaround I can use the curly coding from CMD:
>>%tmpfn% %cmd% /?
but the question is: What is going on here ?
I think percentage signs should be forbidden in file specifications, but M$ has unfortunately allowed that.
 
I think part of the answer is that the parser “knows” that variable expansion should be deferred for a few specific commands, and BDEBUGGER is one of those commands.

BDEBUGGER would normally pass your variable reference unchanged, percent signs and all, to the child shell, which will be responsible for expanding it.
 
I think Charles is correct. But (funny) my results are a bit different. If "bdebugger" is in a variable, redirection works.
Code:
v:\> bdebugger /? >NUL
Start the batch debugger.

BDEBUGGER [/C BatchFile [arguments]]
        BatchFile: The batch file to debug
        /C(reate file)

v:\> set cmd=bdebugger

v:\> %cmd% /? >NUL

v:\>

It's the same in a BTM.
Code:
v:\> type test.btm
set cmd=bdebugger
%cmd% /? > NUL

v:\> test.btm

v:\>

I wonder why it works differently for you. In any event, I suspect you can get around it with
Code:
( %cmd% /? ) >>%tmpfn%
 
I think Charles is correct. But (funny) my results are a bit different. If "bdebugger" is in a variable, redirection works.
Code:
v:\> bdebugger /? >NUL
Start the batch debugger.

BDEBUGGER [/C BatchFile [arguments]]
        BatchFile: The batch file to debug
        /C(reate file)

v:\> set cmd=bdebugger

v:\> %cmd% /? >NUL

v:\>

It's the same in a BTM.
Code:
v:\> type test.btm
set cmd=bdebugger
%cmd% /? > NUL
v:\> test.btm
v:\>
I wonder why it works differently for you. In any event, I suspect you can get around it with
Code:
( %cmd% /? ) >>%tmpfn%
Thanks Vince, Your Workaround works also well :-)
But You've redirect to NUL, not to a file in a variable !
And I think, that Charles is not correct, because it happens not only at the term BDEBUGGER.
The complete list of the suspects in my System (TCC 22.00.42 x64, Windows 7 Version 6.1.7601) is:
Code:
BDEBUGGER
CASE
DEFAULT
DETACH
DO
ENDSWITCH
EXCEPT
FOR
GLOBAL
IDE
IF
IFF
ON
SELECT

If I run this in the commandline
Code:
Set TempFN=Hello.LST
Do cmd In /L BDEBUGGER CASE DEFAULT DETACH DO ENDSWITCH EXCEPT FOR GLOBAL IDE IF IFF ON SELECT (%cmd% /? >>%tempfn%)
then it produces also the %tempfn% but not Hello.LST. If I run all words as single command, than it is also the same.
And this is the second question,why is it only with this keywords the case ?
 
Last edited:
Thanks Vince, Your Workaround works also well :-)
But You've redirect to NUL, not to file in a variable !
I figured it would be the same as with a file since the nul device is opened in the same way that a file is opened. Does the workaround work for you with a filename?
 
I figured it would be the same as with a file since the nul device is opened in the same way that a file is opened. Does the workaround work for you with a filename?
I repeat my Answer:
Thanks Vince, Your Workaround works also well :smile:
I meant - like mine with the >>%tmpfn% %cmd% /?
But what happened on Your system, if You run the script (without the workarounds) ?
 
When I run your script, first I see (red is standard error)
2391


Then the GUI help starts on the TPIPE page, and LIST starts, showing me the first page of output. But LIST is DEAD; no keys work (except Ctrl-C to end it).
 
I was pressing the wrong keys. Many entries are empty, as you said. I do get a file named "%tmpfn%". It contains the quick help for these (and only these): BDEBUGGER, CASE, DEFAULT, DETACH, DO, ENDDO, ENDSWITCH, EXCEPT, FOR, GLOBAL, IDE, IF, IFF, ENDIFF, ON, and SELECT.
 
I was pressing the wrong keys. Many entries are empty, as you said. I do get a file named "%tmpfn%". It contains the quick help for these (and only these): BDEBUGGER, CASE, DEFAULT, DETACH, DO, ENDDO, ENDSWITCH, EXCEPT, FOR, GLOBAL, IDE, IF, IFF, ENDIFF, ON, and SELECT.
Ahemm ahemm .... same result as here :cool:
 
You might try a different approach. When it's done, look at BIGHELP.TXT.
Code:
setlocal

:: each command on a separate line
? | tpipe /replace=4,0,0,0,0,0,0,0,0," *?","\n" > clip:

set lines=%@inc[%@lines[clip:]]

setarray /f a[%lines]

echo @EXECARRAY returned %@execarray[a,type clip:] > nul

do i=0 to %@dec[%_execarray] | tee bighelp.txt
    :: these three are problematic
    if "%a[%i]" eq "TPIPE" .or. "%a[%i]" eq "ECHO" .or. "%a[%i]" eq "ON" iterate
    echo %a[%i]
    %a[%i] /?
    echo %@repeat[=,%@dec[%_columns]]
enddo

unsetarray a

quit
 
You might try a different approach. When it's done, look at BIGHELP.TXT.
Many thanks Vince, You moved me up to another level :joyful:
I did'nt know, that I can use CLIP: like a file ! Is that mentioned anywhere in the Manual ?
Also I like TPIPE, but it is a monster, very hard to tame :mad:
Because the TPIPE manual is very concise, no explanation, few examples, but this is stuff for another discussion
Another problem is, that the output with TEE changes some OEMs :
2395


So I've slightly reformed Your brilliant piece of Code:
Code:
Setlocal
:: each command on a separate line
  ? | TPipe /replace=4,0,0,0,0,0,0,0,0," *?","\n" >CLIP:
IF %_BDEBUGGER EQ 1 Echo %@INC[%@LINES[Clip:]] Zeilen in `CLIP:`
IF %_BDEBUGGER EQ 1 Unsetarray /Q arCmds
Setarray /F arCmds[%@LINES[Clip:]]
Echo @EXECARRAY returned %@EXECARRAY[arCmds,Type CLIP:] >nul
Echo TCC Befehele und Quickhelps >%cmdlistname%
Echo %@REPEAT[=,%@DEC[%_COLUMNS]] >>%cmdlistname%
Do z=0 To %@DEC[%_EXECARRAY]
::  Exclude some  problematics
  If "%arCmds[%z%]" EQ "?" ITERATE
:: ECHO ECHOERR ECHOS ECHOSERR ECHOX ECHOXERR
  If "%@LEFT[4,%arCmds[%z%]]" EQ "ECHO" ITERATE
  Screen %_row %_column %arCmds[%z%] ^r^n >>%cmdlistname%
  (%arCmds[%z%] /?) >>%cmdlistname%
  Echo %@REPEAT[=,%@DEC[%_COLUMNS]] >>%cmdlistname%
Enddo
Unsetarray arCmds
Quit
 
I made some changes too.
Code:
setlocal

:: each command on a separate line
? | tpipe /replace=4,0,0,0,0,0,0,0,0," *?","\n" > clip:

do line in @clip: | tee bighelp.txt
    if %@regex["TPIPE|^ON$|^ECHO|\?",%line] == 1 iterate
    echo %line
    %line /?
    echo %@repeat[=,%@dec[%_columns]]
enddo

quit
 
Vince, I love this compacting and "Elegancing" of Coding, You'd give me the second "kick" in
redirection and piping :happy:
But as before mentioned, I must refomate the code, because TEE make problems with
the OEM-Codes (ÄÖÜßäöü§) and it comes to an error, because the last line in @CLIP: is
empty.
Code:
Setlocal
:: each command on a separate line
  ? | tpipe /replace=4,0,0,0,0,0,0,0,0," *?","\n" > clip:
  >BigQuickHelp_4a.txt
  OPTION //UTF8=Yes
  Do line in @CLIP:
    If "%line%" == "" ITERATE
    If %@REGEX["TPIPE|^ECHO|\?",%line] == 1 ITERATE
    Screen %_row, %_column,%line ^n^r | TEE /A BigQuickHelp_4a.txt
    %line /?
    (%line /?) >>BigQuickHelp_4a.txt
    Echo %@repeat[=,%@dec[%_columns]] | TEE /A BigQuickHelp_4a.txt
  EndDo
Quit
But I have no problems here with the ON keyword, what happens on Your side ?
And, before I forget it, is the CLIP:-Device locked during the process ?
The reason, why I'm transport the content of the clipboard into an array as fast as
possible was, that I fear it can changed by another process, during I read it out.
 
I'm echoing the command name (echo %line) before getting the help. ECHO ON doesn't echo ON.
 
I'm echoing the command name (echo %line) before getting the help. ECHO ON doesn't echo ON.
Remember this trick from the bad old days ....?
Code:
echo.%line

Peter, have you tried with option //unicodeoutput=yes set?
 
do line in @clip: | tee bighelp.txt

Can tee append or does it always create a new file?

I'd like to have bighelp.txt start with the full version information, then append the result of the do loop....
 
do line in @clip: | tee bighelp.txt

Can tee append or does it always create a new file?

I'd like to have bighelp.txt start with the full version information, then append the result of the do loop....
TEE /A
 
Remember this trick from the bad old days ....?
Code:
echo.%line

Peter, have you tried with option //unicodeoutput=yes set?
Charles, Your "Bad-Old-Days-Trick" is working well and the Unicode output with TEE works also :eek:.
I'm excited :smile:
 
That sort of rings a bell. Is it foolproof?
I doubt it; they keep inventing better fools.

echo. is actually documented in the help file. echo.%var% is not — but I imagine it's the same kludge in the code.
 
Back
Top