Advanced Batch features via auxiliary .exe programs

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Advanced Batch features via auxiliary .exe programs

#31 Post by sambul35 » 07 Mar 2016 06:50

Aacini wrote:I posted the TextColor.exe program on July/2012; this means that you are the first person that reported this bug in more than 3 and a half years! This caused me conflicting feelings ("Thank you for reporting it" :) "Why nobody reported it before?" :( ). This type of details give me a measure of how much some of my programs are really used and is one of the reasons that discourage me from making updates to the already posted utilities, documentation, method of use they, etc.

Demand for making batches and "batching" skills are exceedingly rare commodity nowadays with proliferation of modern programming languages on one side, and AutoIt clicking techniques on the other. It doesn't mean the value of your numerous artful contributions is diminishing. I just recently wrote a relatively complex (for me) batch after a few years break. Many skills were forgotten except the desire to make it at a sound level. Not surprising, each small piece of that code required a separate approach to stick, in fact I was learning batching all over again in a self-training Q&A session. Yours, D.Benham's and others concise explanations on Stackoverflow and this forum, and SS64 Cmd Reference served very well. Peaces of your always elegant code provided or led to great ideas or direct solutions for many.

Look how increasingly popular among readers are getting several Basic Tasks covering threads I recently started on this forum, most getting about 200 extra hits per day. Some may think they answered or ignored my personal questions, but fast growing hits tell these are typical coding questions faced by inexperienced batchers, indicating lack of published basic batching methodology exposed through typical tasks and code structure rather than command reference. This tells, batching folks are commonly facing the same Cmd shell limitations, need to find typical ways to address them, and in fact finding them in your and others answers and code. What I'm missing now is almost total lack of info about the OP on the web. The manner to express thoughts hints he's a university math or programming professor. To make your auxiliary programs more popular, may I kindly suggest to include references to them in relevant Stackoverflow answers. Please write MORE brilliant code to compensate well known limitations of Cmd shell. :wink:
Last edited by sambul35 on 17 Mar 2016 19:46, edited 1 time in total.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Advanced Batch features via auxiliary .exe programs

#32 Post by Aacini » 07 Mar 2016 14:58

First of all: @Ed, @aGerman, @miskox, @foxidrive, @mirrormirror, @sambul35 and others: you are welcome! I appreciate your kind words...


miskox wrote:Any ideas why first colorshow.exe shows "-" instead of "|"?

Thanks.
Saso

The original version of these programs, written on 2012, was developed to manage Ascii characters, so they suffer the same problems of other text-based programs when the given vs. displayed characters does not match the current code page. The simplest solution is to use Ascii code numbers instead literal characters to show characters in the 128-255 range.


I am working now in the long-awaited creation of a simpler method to download these programs via a single .zip file (or other ways). However, before that I would like to review and update some programs, like introducing the option to define the filler character in <wide> option for Show.exe and ColorShow.exe programs (suggested by mirrormirror), or post in this thread some auxiliary programs that were originally posted elsewhere (like GetInput.exe, GetFileType.exe, FilePointer.exe and TruncateFile.exe), with a more complete documentation.

Also, a new auxiliary program is almost ready, so I will post it here very soon. I am pretty sure you will like it very much, like me! :D Hint: it is called printf.exe... 8)

Antonio

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

Re: Advanced Batch features via auxiliary .exe programs

#33 Post by aGerman » 07 Mar 2016 15:33

printf.exe

I'm curious about it :)

Regards
aGerman

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Advanced Batch features via auxiliary .exe programs

#34 Post by Aacini » 07 Mar 2016 15:44

@aGerman: its display output capabilities are described here. The other half is the evaluation of arithmetic expressions... :mrgreen:

Antonio

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Re: Advanced Batch features via auxiliary .exe programs

#35 Post by mirrormirror » 07 Mar 2016 16:17

To make your auxiliary programs more popular, may I kindly suggest to include references to them in relevant Stackoverflow answers.

This is how I originally found colorshow - from an SO post.
However, before that I would like to review and update some programs, like introducing the option to define the filler character in <wide> option for Show.exe and ColorShow.exe programs

Well, thank you - looking forward to this. If it is simple, it would also be nice to be able to use a literal string as mentioned before:

Code: Select all

colorshow has the useful ability to display text from a variable within another block of text like this:
colorshow MyVar:+100
It would be nice to be able to also do this using a literal string like:
colorshow "hello world":+100
Also in this mode, it always displays the text within a block of [SPACES]. It would be nice to be able to choose another character instead of a space. For examle. In order to display something like this:

I also have one more comment. Do you think it would make sense to combine the functionality of colorshow.exe and textcolor.exe into one program?
If, for time considerations, you would like help with documentation or packaging these up just let us know. I would be willing to help.

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

Re: Advanced Batch features via auxiliary .exe programs

#36 Post by aGerman » 07 Mar 2016 17:06

@Antonio
Yeah I'm pretty familiar with printf. I'm more curious about your implementation of the format specifiers as part of the passed arguments. I did something similar with my own timeout tool that is able to display a user-defined message with embedded countdown. But I think the correct parsing of arithmetic expressions is even more complicated. Operator precedence, nested parentheses, unary plus and minus, scientific notation of floating point numbers, ... I have to admit that once I tried it I gave up frustrated :lol: Good luck :!:

Regards
aGerman

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Advanced Batch features via auxiliary .exe programs

#37 Post by Aacini » 07 Mar 2016 20:00

mirrormirror wrote:
To make your auxiliary programs more popular, may I kindly suggest to include references to them in relevant Stackoverflow answers.

Well, every time I had an opportunity to post a link to these programs in SO, I did it. The problem is that frequently I am reluctant to suggest an .exe program solution for simple Batch tasks (unlike Dave, that promotes his JREPL.BAT even in the most simple replacement requests :roll: ). Anyway, many people want not or can not use third party applications in their Batch files, so the promotion of these .exe auxiliary programs in SO is more difficult...


mirrormirror wrote:
However, before that I would like to review and update some programs, like introducing the option to define the filler character in <wide> option for Show.exe and ColorShow.exe programs


Well, thank you - looking forward to this. If it is simple, it would also be nice to be able to use a literal string as mentioned before

Well, no. The additon of a filler character instead space is very simple: just change the space already used now by another character defined by a code given in the parameter, but the other change is more complex. It is much simpler to insert the desired string in a variable and then use the variable in ColorShow.exe (and I don't like the <"literal":option> notation anyway)...


mirrormirror wrote:I also have one more comment. Do you think it would make sense to combine the functionality of colorshow.exe and textcolor.exe into one program?

I am afraid I don't understand what you mean with that. ColorShow.exe show caracters in given colors independently of any other current setting (like the color set by COLOR command). TextColor.exe set the color that will be used by posterior commands, including the standard Windows/DOS cmd.exe commands, so its function is similar to COLOR command. I don't see how these two different operations could be merged in a single program...


mirrormirror wrote:If, for time considerations, you would like help with documentation or packaging these up just let us know. I would be willing to help.

Well, thanks a lot for the offer, but the required tasks are basically a compilation job difficult to split between several people... However, if you want to help you may read this whole thread using "novice's eyes" and indicate at which part I use something that was not explained before or that is not clear enough; this will help me to improve the documentation.



aGerman wrote:Yeah I'm pretty familiar with printf. I'm more curious about your implementation of the format specifiers as part of the passed arguments. I did something similar with my own timeout tool that is able to display a user-defined message with embedded countdown. But I think the correct parsing of arithmetic expressions is even more complicated. Operator precedence, nested parentheses, unary plus and minus, scientific notation of floating point numbers, ...

In the implementation of this program I used two interesting tricks: 1. I am not emulating printf function; my program is a wrapper for the Win-API printf C run time function that just take the parameters given to the program, convert they to the equivalent arguments for the printf function (using a couple simple rules), and invoke it. That is it! 2. I am using Reverse Polish Notation (RPN) logic for the arithmetic expression (using the same stack that will be used to pass the arguments to printf); this point eliminate all problems related to operator precedence, nested parentheses, etc. Really, the most complex part of this program is the reading and conversion of numbers...

The program is practically complete; just a few minor details in the code and a couple large sections in the documentation/examples needs to reviewed.

Antonio

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Re: Advanced Batch features via auxiliary .exe programs

#38 Post by mirrormirror » 07 Mar 2016 20:56

I am afraid I don't understand what you mean with that. ColorShow.exe show caracters in given colors independently of any other current setting (like the color set by COLOR command). TextColor.exe set the color that will be used by posterior commands, including the standard Windows/DOS cmd.exe commands, so its function is similar to COLOR command. I don't see how these two different operations could be merged in a single program...

I mean that the functionality of TextColor is simple - as I understand it these are the available options:
TextColor [/E] [bf]
(and the /E option doesn't seem to work on my system either :( )
I am suggesting that you could incorporate this functionality into colorshow something like this:
colorshow.exe [bf]
And if no subsequent text or params were included, it would change the subsequent text color in the console the same way "textcolor" does. It would be great if the /E option worked but I saw your notes in the accompanied text file.
Well, no. The additon of a filler character instead space is very simple: just change the space already used now by another character defined by a code given in the parameter, but the other change is more complex. It is much simpler to insert the desired string in a variable and then use the variable in ColorShow.exe (and I don't like the <"literal":option> notation anyway)...

That's fine, but just to make it clear what I am suggesting. I have some code like this (below) and I must first put write "%1" into a variable before using it how I would like. I am asking if it would be easy to change colowshow so that the following syntax would work:

Code: Select all

call :writelog "my error message"
exit /b

:writelog
   colorshow /4E "%1":100
goto:eof

And just to add, I am happy with these utilities as they are. There are work-a-rounds for whatever small issues have been found so even if you don't update them I will still use them :)

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Re: Advanced Batch features via auxiliary .exe programs

#39 Post by mirrormirror » 07 Mar 2016 21:10

just adding another example of syntax that would be nice to use:

Code: Select all

for /f %%a in ('file.txt') do colorshow /4F "%%a":100

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Advanced Batch features via auxiliary .exe programs

#40 Post by Aacini » 07 Mar 2016 22:09

Ok, I understand you now: you propose to eliminate TextColor.exe program entirely and insert its functionality in ColorShow.exe program, right? This is an interesting suggestion! I will evaluate it...

About your code examples, the work-arounds are really simple:

Code: Select all

call :writelog "my error message"
exit /b

:writelog
   set "msg=%~1"
   colorshow /4E msg:100
goto:eof

and:

Code: Select all

for /f %%a in ('file.txt') do set "line=%%a" & colorshow /4F line:100

Remember that all my .exe programs that process variable names does not require Delayed Expansion (in the same way as SET /A command).

Antonio

PS - As you know, in standard Batch you can not do something like this:

Code: Select all

set part="0123456789ABCDEF":~10,3

... to try to assign "ABC" to "part".

If you could do something like this: ColorShow "my error message":100 I am pretty sure that sooner or later a novice would try the example above, just for association of ideas...

EDIT: Here there is an example (and another one) of the type of errors that the association of ideas like these ones may cause...

On the other hand, the requirement to assign a string literal to a variable in order to apply a modifier to it is something well established in Batch files, so ColorShow.exe program just adhere to such rule.
Last edited by Aacini on 02 Jun 2016 06:43, edited 3 times in total.

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

Re: Advanced Batch features via auxiliary .exe programs

#41 Post by aGerman » 08 Mar 2016 13:26

Reverse Polish Notation

Interesting read :!: Years ago when I heard about it I confused it with Hungarian Notation for some reason and didn't pay attention to it. Shame on me :roll:

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Advanced Batch features via auxiliary .exe programs

#42 Post by Aacini » 08 Mar 2016 13:33

Err... Didn't you knew Hewlett Packard calculators?

Antonio

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

Re: Advanced Batch features via auxiliary .exe programs

#43 Post by aGerman » 08 Mar 2016 13:39

Not at all. Thanks for pointing!

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Advanced Batch features via auxiliary .exe programs

#44 Post by Aacini » 14 Mar 2016 16:15

The next post appears in a Private Message that miskox sent me. I am copying it here because the answer solve a problem that other users may also have.

miskox wrote:Hi again Antonio!

I understand your solution with the ASCII code for a desired character but unfortunately this is not good for me. Let me show you why:

I have this as part of my .bat file. Then I do a FINDSTR for "TTTTT" with /B and put it in a temporary file.

Code: Select all

TTTTTProlet_2+12;   ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄż
TTTTTProlet_2+12;   ł     ł82   ł   88ł     ł;_82_,10,2}_88_,19,2};
TTTTTProlet_2+12;   ł     Ă ÄÄÄÄÁÄÄÄÄ ´     ł
TTTTTProlet_2+12;   ł   83    łłłł     87   ł;_83_,7,2}_87_,22,2};
TTTTTProlet_2+12;   ĂÄÄÄÄÄ´           ĂÄÄÄÄÄ´
TTTTTProlet_2+12;   ł   84             86   ł;_84_,7,2}_86_,22,2};
TTTTTProlet_2+12;   ł     ĂÄÄÄ ÄÂDVIG ´     ł
TTTTTProlet_2+12;   ł     ł  85 ŔÄÄÄÄÄ´     ł;_85_,12,2};
TTTTTProlet_2+12;   ł     ł           ł     ł
TTTTTProlet_2+12;   ŔÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄŮ


Then I parse each line: tokens=1,2,3. If token3 is empty then I just display token2.

If token3 is not empty then I parse it and check if current appartment number (for example 82 above) is part of the token2 (_82_) then I get this number's offset and length (10 and 2). Then I perform make three variables:

part1=left part (before 82)
part2=appartment number (82)
part3=everything that is after the appartment number (after 82)

then this code is executed:

Code: Select all

colorshow.exe /07 "%part1%" /E0 "%part2%" /07 "%part3%"


I want the appartment number to be highlighted. (depends on the appartment number of the currently selected record in a main file).

So using ASCII codes causes problems because I don't know where these codes (128-255) are.

Aacini wrote:Of course, the exact characters displayed on the screen depends on the current code page, as usual in all Ascii-build programs (as opposed to Unicode-build ones).


Characters displayed on the screen are correct.

So you say there is not way to display these 128-255 codes correctly?

Put this in a file a.a:

Code: Select all

   ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄż
   ł     ł82   ł   88ł     ł
   ł     Ă ÄÄÄÄÁÄÄÄÄ ´     ł
   ł   83    łłłł     87   ł
   ĂÄÄÄÄÄ´           ĂÄÄÄÄÄ´
   ł   84             86   ł
   ł     ĂÄÄÄ ÄÂDVIG ´     ł
   ł     ł  85 ŔÄÄÄÄÄ´     ł
   ł     ł           ł     ł
   ŔÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄŮ


and now

Code: Select all

type a.a


Code: Select all

   ┌─────┬─────┬─────┬─────┐
   │     │82   │   88│     │
   │     ├ ────┴──── ┤     │
   │   83    ││││     87   │
   ├─────┤           ├─────┤
   │   84             86   │
   │     ├─── ─┬DVIG ┤     │
   │     │  85 └─────┤     │
   │     │           │     │
   └─────┴───────────┴─────┘


Thank you.
Saso



Ok. I completed some tests on this topic. As I said you: "the exact characters displayed on the screen depends on the current code page"; this way, the important point here is identify the characters that are displayed on the screen by ColorShow.exe program in the current code page, right?

To do that, I started with a text file that contain all Ascii printable characters, from 32 to 255, separated in rows of 16 characters each to easily identify them. This is such file as appears in Windows Notepad:

Code: Select all

2-  ! #$%&'()*+,-./
3- 0123456789:;<=>?
4- @ABCDEFGHIJKLMNO
5- PQRSTUVWXYZ[\]^_
6- `abcdefghijklmno
7- pqrstuvwxyz{|}~
8- €‚ƒ„…†‡ˆ‰Š‹ŒŽ
9- ‘’“”•–—˜™š›œžŸ
A-  ¡¢£¤¥¦§¨©ª«¬­®¯
B- °±²³´µ¶·¸¹º»¼½¾¿
C- ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ
D- ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
E- àáâãäåæçèéêëìíîï
F- ðñòóôõö÷øùúûüýþÿ

... and this is the same file when it is displayed in the screen with TYPE command:

Code: Select all

C:\> type Char256-32.txt
2-  ! #$%&'()*+,-./
3- 0123456789:;<=>?
4- @ABCDEFGHIJKLMNO
5- PQRSTUVWXYZ[\]^_
6- `abcdefghijklmno
7- pqrstuvwxyz{|}~⌂
8- ÇüéâäàåçêëèïîìÄÅ
9- ÉæÆôöòûùÿÖÜø£Ø׃
A- áíóúñѪº¿®¬½¼¡«»
B- ░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐
C- └┴┬├─┼ãÃ╚╔╩╦╠═╬¤
D- ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀
E- ÓßÔÒõÕµþÞÚÛÙýݯ´
F- ­±‗¾¶§÷¸°¨·¹³²■

However, we don't care how these characters are displayed by Notepad or TYPE command, but how these characters are displayed by ColorShow.exe program, right?

Code: Select all

C:\> for /F "delims=" %a in (Char256-32.txt) do @ColorShow "%a"  13 10
2-  ! #$%&'()*+,-./
3- 0123456789:;<=>?
4- @ABCDEFGHIJKLMNO
5- PQRSTUVWXYZ[\]^_
6- `abcdefghijklmno
7- pqrstuvwxyz{|}~
8- óÚÔõÓÕþÛÙÞ´¯ý─┼
9- ╔µã¶÷‗¹¨ Í▄°úÏÎâ
A- ßݾ·±Ð¬║┐«¼¢╝í½╗
B- ªªªªª┴┬└®ªª++óÑ+
C- +--+-+Ò├++--ª-+ñ
D- ­ð╩╦╚i═╬¤++ª_ª╠»
E- Ë▀ÈʧıÁ■Ì┌█┘²¦»┤
F- ¡▒=¥Âº¸©░¿À╣│▓ªá

As we can see, in this screen all line drawing characters appears, although in different positions. If we compare this screen vs. the original file as displayed in Notepad (that is the text editor I use to create these files), we can know what are the equivalent characters that should be used in order to display a certain character in the screen using ColorShow program.

After that, I copied your "wanted" file into Notepad, that looks like this:

Code: Select all

   ┌─────┬─────┬─────┬─────┐
   │     │82   │   88│     │
   │     ├ ────┴──── ┤     │
   │   83    ││││     87   │
   ├─────┤           ├─────┤
   │   84             86   │
   │     ├─── ─┬DVIG ┤     │
   │     │  85 └─────┤     │
   │     │           │     │
   └─────┴───────────┴─────┘

... and then replaced each line-drawing character by the equivalent character after seek it in the previous screen and copied the corresponding character from the Char256-32.txt file (as explained before). This is the resulting file, as it appears in Notepad:

Code: Select all

   éŽŽŽŽŽ¶ŽŽŽŽŽ¶ŽŽŽŽŽ¶ŽŽŽŽŽ¨
   ü     ü82   ü   88ü     ü
   ü     Ç ŽŽŽŽµŽŽŽŽ ï     ü
   ü   83    üüüü     87   ü
   ÇŽŽŽŽŽï           ÇŽŽŽŽŽï
   ü   84             86   ü
   ü     ÇŽŽŽ Ž¶DVIG ï     ü
   ü     ü  85 ·ŽŽŽŽŽï     ü
   ü     ü           ü     ü
   ·ŽŽŽŽŽµŽŽŽŽŽŽŽŽŽŽŽµŽŽŽŽŽë

... and this is how the file appears in the screen when it is displayed via TYPE command:

Code: Select all

C:\> type input.txt
   ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄ¿
   ³     ³82   ³   88³     ³
   ³     Ã ÄÄÄÄÁÄÄÄÄ ´     ³
   ³   83    ³³³³     87   ³
   ÃÄÄÄÄÄ´           ÃÄÄÄÄÄ´
   ³   84             86   ³
   ³     ÃÄÄÄ ÄÂDVIG ´     ³
   ³     ³  85 ÀÄÄÄÄÄ´     ³
   ³     ³           ³     ³
   ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÙ

However (again): we don't care how this file is displayed in Notepad or by TYPE command, but how it is displayed by the ColorShow program:

Code: Select all

C:\> for /F "delims=" %a in (input.txt) do @ColorShow "%a"  13 10
   ┌─────┬─────┬─────┬─────┐
   │     │82   │   88│     │
   │     ├ ────┴──── ┤     │
   │   83    ││││     87   │
   ├─────┤           ├─────┤
   │   84             86   │
   │     ├─── ─┬DVIG ┤     │
   │     │  85 └─────┤     │
   │     │           │     │
   └─────┴───────────┴─────┘

After that, I wrote this test Batch file just to complete this answer:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

for /F "delims=" %%A in (input.txt) do (
   set "line=%%A"
   for /F "tokens=1,2 delims=;" %%a in ("!line:82=;!") do (
      if "%%b" equ "" (
         colorshow "!line!"  13 10
      ) else (
         set "part1=%%a"
         set "part2=82"
         set "part3=%%b"
         colorshow.exe /07 "!part1!" /E0 "!part2!" /07 "!part3!"  13 10
      )
   )
)

... and this is the output:

Image

VERY IMPORTANT: I run previous tests using the standard code page in my computer, that is 850. I also did some tests changing the current code page, and I realized that the "frame drawing" characters does NOT appear in all code pages. In particular, it appears in code page 437 in different positions, and some vertical lines does not appear in code page 852. The simplest solution to this point is change code page to 850 before run your program...

Antonio

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Advanced Batch features via auxiliary .exe programs

#45 Post by miskox » 15 Mar 2016 12:54

Thank you Aacini for this test - very good idea!

Saso

Post Reply