1.

Solve : Please test this batch script.?

Answer»

The script uses Extended ASCII codes and I want to determine if the default codes differ across Windows systems especially Vista and Win 7 variants.

Code: [SELECT]@echo off
cls
setlocal enabledelayedexpansion

set tl=┌&set tr=┐&set bl=└&set br=┘&set up=│

for /l %%▓ in (1,1,8) do echo.

set var=Now is the time
call :display

echo.
set var=For all good men to
call :display

echo.
set var=Come to the aid of their party.
call :display

echo.
set var=......Press any key to continue......
call :display


pause>nul
cls
exit/b

:display
:: Get length of var..
set var1=%var: =%■

:start
call set chr=%%var1:~%pos%,1%%
if !chr!==■ goto finis
set /a pos+=1
goto start

:: Calc number of spaces to centralize text box across line..
:finis
set /a spaces=((80-%pos%)-2)/2
for /l %%Σ in (1,1,%spaces%) do set spaces1=!spaces1!∩

:: Display text box..

set /a pos+=2
for /l %%Σ in (1,1,%pos%) do set line=!line!─

echo %spaces1:∩= %%tl%%line%%tr%
echo %spaces1:∩= %%up% %var% %up%
echo %spaces1:∩= %%bl%%line%%br%

set spaces=&set spaces1=&set line=&set pos=
goto :eof


Expected output is:


Many thanks.
It just opens and closes really quick. I saw something about % was unexpected at this timeComputeruler - thank you. There seems to be a conflict between Ansi and Unicode chars when copying/pasting using Notepad. The script runs perfectly locally as I use Edit.com as preferred text editor. I'll try different coding as a workaround to allow copy/paste with Notepad.

Thanks again & all the best for the festive season.

.

Using Windows XP SP3 cmd.exe

(1) I copied it into UltraEdit32 and saved it as dt1.bat.



(2) I OPENED a command window in the folder & typed the name.



(3) I pressed ENTER



I am using Consolas as my console window font. (Not every console font has the same characters above ASCII 127.)

I pasted it into SciTE, the other editor I use a lot, and saved it as dt2.bat. Same results.

Then I fired up Notepad which I hardly ever use, pasted it in, and when I chose to save as dt3.bat I got a dialog saying that since the file contained Unicode characters, information would be lost if I chose to save it with ANSI encoding, & to cancel and pick a different encoding so I chose Unicode and when I ran the thus-saved batch I got an error

Code: [Select]'■@' is not recognized as an internal or external command,
operable program or batch file.


Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.







Salmon Trout - thank you for your sterling efforts. You will note that in line 5 of the script you posted the Extended Ascii codes have changed, probably during the pasting operation, therefore the result is not what I'm trying to achieve.

I have found that the Extended Ascii codes are changed when the script is pasted into Edit.com running in Cmd.exe so the output there is not what is wanted, but, when the script is pasted into Edit.com running in Command.com the codes are properly pasted and the output is aok.

Would you care to:
(a) Copy the script to your clipboard.
(b) Open Command.com
(c) Start Edit.com
(d) Paste the script into Edit.com
(e) Save the script as Something.bat (or .com)
(f) Run the file in Command.com and Cmd.exe
(g) Post your result

A big ask, your result will be appreciated.





Quote from: Dusty on December 25, 2009, 01:21:03 PM

(a) Copy the script to your clipboard.
(b) Open Command.com
(c) Start Edit.com
(d) Paste the script into Edit.com
(e) Save the script as Something.bat (or .com)
(f) Run the file in Command.com and Cmd.exe
(g) Post your result

command.com -> edit.com -> pasted -> saved as bat script

(1) run in command.com (command window font set to 7x12 raster font)



(2) same batch run in cmd.exe (7 x 12 raster font)






Quote from: Dusty on December 25, 2009, 01:21:03 PM
I have found that the Extended Ascii codes are changed when the script is pasted into Edit.com running in Cmd.exe so the output there is not what is wanted, but, when the script is pasted into Edit.com running in Command.com the codes are properly pasted and the output is aok.

cmd supports- or tries to support, unicode. command.com does not. Either way, you cannot run edit.com from within cmd; it spawns command.com to run it anyway, not sure exactly where the issue lies, but I assure you it has to do with unicode/ANSI support.

If you save as ANSI encoded in any text editor your batch will work (given that the fonts match)Salmon Trout - Thank you again, that's exactly what I was trying to replicate.

BC-P - sorry, I'm not sure what you mean. Quote
If you save as ANSI encoded in any text editor your batch will work (given that the fonts match)

It's been shown that attempting to save the script using Notepad brings up the warning shown below even when Ansi encoding is selected. Selecting Unicode MAKES the script unusable.



Quote from: Salmon Trout on December 25, 2009, 03:29:24 AM
Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.
Quote from: BC_Programmer on December 25, 2009, 06:36:30 PM
Quote from: Salmon Trout
Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.


Yeah, sure, the script runs but does not produce the REQUIRED output because the Extended Ascii chars have changed as shown in Salmon Trout's screen capture in reply #3. After saving the copy/post into Edit.com running in Command.com the script runs correctly and produces the required output as shown in Salmon Trout's reply #5.

Thank you for your interest, would you run the script in Vista and post your results please?

Quote from: Dusty on December 25, 2009, 10:01:12 PM
Yeah, sure, the script runs but does not produce the required output because the Extended Ascii chars have changed as shown in Salmon Trout's screen capture in reply #3.


none of the character codes were changed.

Quote
I am using Consolas as my console window font. (Not every console font has the same characters above ASCII 127.)

and then, in the later screenshots:

Quote
(command window font set to 7x12 raster font)


this is the key.

Anyway, I ran it on mine, and even though I was using Raster fonts, I still got the same characters as Salmon Trout:




I decided to investigate. the issue is rooted solely in code pages. When I visited character map and went to the code that corresponded to the character I saw, it was there, within the same set of fonts. under the same code. This was odd. BUT! I changed the "character" in character maps "advanced" section to "DOS-US" and the line drawing characters were there.

Since I'm on Vista x64 I cannot run edit and it isn't included with my OS. I was able to get agreeable results by "cheating" what I did, was I copied the batch file to the clipboard, used the command "copy con D:\test.bat" and used the cmd "paste" feature, followed by Control-Z and enter. I did end up with an extra @echo off line at the top, but it has no impact on the functionality.

I ran the batch resulting from this, and success!:



So it works, as long as the batch os created properly, in vista x64.

As it is now, there are a LOT of encoding conversions to get it on other machines, copy from browser, paste to editor, etc. So, I decided to simply plop it in a text file and attach it as is. this way, the file should be relatively untainted by any data manipulation performed by the OS during copy paste, and it will be easier for others using other operating systems to test... in fact... test on my win 7 laptop:



Note: these are both x64 systems; I'd imagine it will work fine on x86 versions of these Operating Systems, too.






[Saving SPACE, attachment deleted by admin]BC_P - thank you, the results you produced are greatly appreciated.

D..


Discussion

No Comment Found