General comment - Apologies for not being attentive to this post but I have been distracted with other life issues lately which needed immediate attention & action
@pieh-ejdsch - Please excuse my ignorance here I'm not quite sure what you getting at here. I clicked on the link you have kindly provided as you seem to be referring to Pushd & Popd in 9X. When you goto the link it illustrates a rather large but well crafted batchfile which I assume would take a fair amount of time to run? Can you elaborate a little more as to the point you are trying to get across please?
@Penpen - Many thanks for the explanation as to how to test for "TMP" etc very useful. I kinda suspected that was the situation with For within the Win9xdos scenario. Just for a workaround for possibly others who may visit this post I have found a program by Bruce Gunthrie called Fortune which apparently adds additional functionality to the for command under win9Xdos, however within the context of this post & those contributing to this post, it may be deemed an un-neceesary overhead in terms of using yet another external program. What I have learned from this is maybe an precautionary integrity check needs to be performed to test if these TEMP/TMP are functional as this script tends to use the TMP/TEMP quite a lot?
In respect of the batch compilers point taken & understood, it's just if some of this stuff could be condensed into a single com/exe file would have possibly helped, your advice and experience are valuable in such matters?
Yes the DEBUG option is
"VERY" Very interesting & debug programs or scripts can be compiled into functional com files I think if under 64Kbs if memory serves me right? In respect of the Debug Script you have provided can I share in "jfl"'s exuberance in what you have produced I would absolutely love to learn the capabilities of Debug in writing small scripts and programs & the Hybrid capability opens all sorts of additional doors, to new possibilities.
It almost warrants a separate section of Dostips, Hint Hint in a sub-classication forum for people to learn & share ideas in respect of Debug & hybriding with batch along with things like this I've seen: there is also an enhanced DEBUG program called DebugX I think I first came across it in one of the Starmans web pages which is compatable with all off the existing MS Debug commands & Some.
Code: Select all
@echo off
:: ECHOO.COM program
chcp 437 >nul
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR)EEEUYRX2Dx=>EKU.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU!WvX0GwUY Wv;ovBX2Gv0ExGIuht6>>EKU.com
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg>>EKU.com
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0>>EKU.com
echoo $31$30$30$25$20$b4$bf$cf$e3$d3$cd$0d$0a>~tmp.txt
chcp 936 >nul
type ~tmp.txt
pause
I personally could not get it to work but allegedly this code builds a program called echoo.com which strips CRLF's from txt files in DOS from within a batch file like SET CWD= or 1st temp file.
Many say it is a dangerous program to play with & for the ignorant like me that certainly would apply. Debug is presant in all OS's up to Win7 (That is windows Os's) Scary, dangerous or not I think it is very relevant & very useful. Would it be safer to run test scripts within a sandbox or would "W" overide the sandbox? Anyway less of the rant & onward. I get excited & carried away sometimes. Anyway your efforts and explanation are very much appreciated "Thankyou" Penpen.
@jfl - Found this script on my travels @
https://pement.org/sed/bat_env.htm
Solution (c): Use DEBUG to create a temporary file.
The following solution requires no user intervention, nor does it require single linefeeds in a DOS batch file. DEBUG.EXE is included in all standard distributions of MS-DOS and is in Windows 95/98 in C:\WINDOWS\COMMAND, so you can use it unless someone has deleted it.
Code: Select all
@echo off
:: assume that the datafile exists already in ANSWER.DAT [Could be pre-made in batch]
echo e 100 "set myvar=" > TEMP.FIL
echo n PREFIX.DAT >> TEMP.FIL
for %%i in (rcx a w q) do echo %%i >> TEMP.FIL
debug < TEMP.FIL
copy PREFIX.DAT+ANSWER.DAT VARIAB.BAT
call VARIAB.BAT
echo Success! The value of myvar is: [%myvar%].
:: erase temp files ...
for %%f in (PREFIX.DAT ANSWER.DAT VARIAB.BAT TEMP.FIL) do del %%f >NUL
Many people are skittish about using DEBUG and rightfully so, since DEBUG can crash a hard drive or delete files and directories. Therefore, here is an explanation of what the previous commands actually do. I obtained these commands from Dan Gookin's Guide to Underground DOS 6.0 (Bantam Books, 1993), pp. 187-190, which tells quite a lot about using DEBUG. For the cautious user, here's what these commands mean to DEBUG:
e 100 "set myvar=" ; at base address 100, Enter this "string"
n PREFIX.DAT ; "n" means set a filename called PREFIX.DAT
rcx ; in Register CX, set the size of the file
a ; filesize A hex (10 bytes) put in register CX
w ; Write the file set by "n", i.e., PREFIX.DAT
q ; Quit DEBUG
Maybe some aspect of the above code could be useful in refinning ideas possibly? The truename presumeably is your file yes, not the inbuilt Windows98SE internal command? Under what circumstances are you able to use your "Truename" program e.g. what OS's is it able to run under & it's any short-comings or limitations & is there a readme help file for syntax flags etc? Your above script also uses Find I see, nothing wrong in that just an observation? Could truename be converted into ascii code like echoo.com above and be embedded within a batch file to run on the fly so to speak?
Someone can correct me if I am wrong in the following statement or amend to suit but is what we are discussing to do with a thing in Unix Bash etc that is referred to as Command-Substitution, BackTicks or sometimes referred to as Backquotes with the ` symbol being used ina generic sense. I believe SED, Unix2dos, AWK, Tr are windows ports that permit this functionality??? I believe in XP cmd a workaround to achieve the same thing uses the SET /P command.
Here's another varient piece of batch code that might prove useful also:
Code: Select all
::Into environment variable
: The following is based on a solution by William Allen so, it was NOT
: a competition about, Who can write this more brief than another. The
: @ECHO OFF was actually working. (Tested on Win98).
:
@echo off> %temp%.\~.bat
for %%e in ( e5'SET'20'X'3D rcx 6 w5 q ) do echo %%e>> %temp%.\~.bat
type %temp%.\~.bat |debug %temp%.\~.bat> nul
echo Hello World>> %temp%.\~.bat
: FIND "ot" < %0>> %temp%.\~.bat
This batch file outputs the "Hello World" text then if I'm not mistaken injects that into a %var%, maybe of some use possibly?
Another thought was from Stdout to embed that within a Var then from the CD> or %0 thingy temp file convert to Var
as very often there seems to be two temporary files setup e.g. SET CWD= with CRLF's removed (to put both statements on one line) and a further temp file with whatever path CD> or %0 redirects then both are combined into SET CD=[& Whatever path] are then setup into a bat file then call command is issued and the Var is SET. However if the Stdout was converted to Var along with [& whatever path] were set to Var both resultant Vars could be Concat like SET CWD="%CD%%[& Whatever path]%" or SET VAR="%VAR1%%VAR2%" I don't know if this would get round the CRLFs in variable format.
And finally I have discoved a Dos Written MASM Assembly program that strips CRLF's but is only 16Bit, however the OP managed to get the majority of the ASM code translated into 32Bit MASM but left out some of the code as a learning exercise for the OP to practice on. So my point is someone with the knowledge to translate 16bit asm code into 32bit MASM & be able to compile the program could have both 16bit & 32bit varients of the same CRLF stripping program. The programs would be an overhead yes & not written in batch but could prove useful. I will not post the MASM Scripts as they are fairly long but will do if someone with the relevant skill set requires me too perhaps in another section of Dostips?
Best Regards David