Search found 2357 matches

by dbenham
25 May 2011 12:00
Forum: DOS Batch Forum
Topic: Variable Question
Replies: 14
Views: 5960

Re: Variable Question

One of the answers to the original questions is imprecise and needs clarification: How long is a variable stored? Until the script ends or it's set to NUL. By default, changes made to a variable persist after the batch file terminates. The changes are not lost until the "DOS" session ends....
by dbenham
25 May 2011 05:15
Forum: DOS Batch Forum
Topic: Menu question
Replies: 3
Views: 2304

Re: Menu question

Actually there is a simpler solution - the value of choice remains unchanged if <Enter> is pressed without entering anything:

Code: Select all

set choice=banana
set /p "choice=Pick your fruit (default=%choice%): "
echo:Your choice is %choice%.


Dave Benham
by dbenham
24 May 2011 09:37
Forum: DOS Batch Forum
Topic: stderr to a file from a batch script
Replies: 1
Views: 3248

Re: stderr to a file from a batch script

Since you are appending data to the log file, I assume you want the log to preserve errors from prior runs. Once the log is created (empty or not) it is not re-created on subsequent runs. So it seems to me you could simply ignore the empty file. The log file will remain empty until the 1st run that ...
by dbenham
23 May 2011 19:39
Forum: DOS Batch Forum
Topic: new functions: :chr, :asc, :asciiMap
Replies: 31
Views: 47318

Re: new functions: :chr, :asc, :asciiMap

Fixed bug in :chr, :hex2str and :rot13 relating to [Solved] Return ANY string across ENDLOCAL boundry - BUG!

Updated code available at the same place as last time.

Dave Benham
by dbenham
23 May 2011 17:18
Forum: DOS Batch Forum
Topic: [SOLVED] SET /a -- Random Number?
Replies: 24
Views: 19892

Re: [SOLVED] SET /a -- Random Number?

Not cool Nit - I seem to recall an expression - "The pot is calling the kettle black". I discourage anyone from using Nitt's naive solution, unless you want your computer executing perhaps thousands of unnecessary loops. Each pass has only a 0.3% chance of getting a number between 0 and 10...
by dbenham
23 May 2011 07:59
Forum: DOS Batch Forum
Topic: [Solved] Return ANY string across ENDLOCAL boundry - BUG!
Replies: 7
Views: 5963

Re: Return ANY string across ENDLOCAL boundry - BUG!

Ahhh, it all makes sense now. Armed with your explanation, I was able to change the algorithm to use J, K, L, M (M for <LF>), and that works as well. I'll probably stick with the numbers, but it helps to understand what is going on.

Thanks Jeb for making everything clear.

Dave
by dbenham
23 May 2011 06:47
Forum: DOS Batch Forum
Topic: [Solved] Return ANY string across ENDLOCAL boundry - BUG!
Replies: 7
Views: 5963

Re: Return ANY string across ENDLOCAL boundry - BUG!

Hi Jeb That doesn't make sense to me. Why would each of the following strings fail with the original code? %%B %%C %%L They don't have an A, so where do the attributes come in to the picture? or why would %%A imply file attributes when there is no ~? It seems like there must be some other mechanism....
by dbenham
23 May 2011 05:36
Forum: DOS Batch Forum
Topic: [Solved] Return ANY string across ENDLOCAL boundry - BUG!
Replies: 7
Views: 5963

Re: Return ANY string across ENDLOCAL boundry - BUG!

Thank you Jeb I replaced the zero line characters ABCL with 2349 in the original test string, and everything works perfectly! The problem seems to be the characters, they are interpreted as flags A=a=file attributes... Where does that come from? Can you explain that a bit more? Dave Benham
by dbenham
22 May 2011 20:43
Forum: DOS Batch Forum
Topic: Delayed Expansion and escapes
Replies: 3
Views: 2405

Re: Delayed Expansion and escapes

As long as you know how many times the character needs to be escaped it's not difficult. The total number of characters is simply a power of 2. 0 escapes = 2^0 = 1 = ! 1 escape = 2^1 = 2 = ^! 2 escapes = 2^2 = 4 = ^^^! 3 escapes = 2^3 = 8 = ^^^^^^^! etc. One problem is it is not always obvious how m...
by dbenham
22 May 2011 20:11
Forum: DOS Batch Forum
Topic: [Solved] Return ANY string across ENDLOCAL boundry - BUG!
Replies: 7
Views: 5963

[Solved] Return ANY string across ENDLOCAL boundry - BUG!

Noooooooo! I just discovered a serious bug in the "magic" code that Jeb developed here :chr, :asc, :str2hex, :hex2str The code is intended to return any string across an ENDLOCAL boundry, whether or not delayed expansion is enabled or disabled. But it doesn't work if the string contains an...
by dbenham
22 May 2011 17:52
Forum: DOS Batch Forum
Topic: Variable Within a Variable
Replies: 5
Views: 2784

Re: Variable Within a Variable

I'm having a hard time figuring out exactly what you want the output to look like. But it sounds like you need to escape the %. Try:

Code: Select all

echo user%%n%%


Dave Benham
by dbenham
22 May 2011 15:59
Forum: DOS Batch Forum
Topic: new functions: :chr, :asc, :asciiMap
Replies: 31
Views: 47318

Re: new functions: :chr, :asc, :asciiMap

I discovered and fixed a bug in both :asc and :str2hex functions. The functions were failing if the input StrVar name collided with a local function variable.

The new version is available at Google Sites: dbenham Files
by dbenham
21 May 2011 18:54
Forum: DOS Batch Forum
Topic: Batch "macros" with arguments
Replies: 73
Views: 68165

Re: Batch "macros" with arguments

I don't remember saying I had problems DREFing more than twice. I said I had successfully tested dereferencing macro1 that calls macro2 that calls macro3. The derefMacro function is designed to handle any number of deref operations, I just haven't tested past 2. (one call loops through and dereferen...
by dbenham
21 May 2011 17:52
Forum: DOS Batch Forum
Topic: Batch "macros" with arguments
Replies: 73
Views: 68165

Re: Batch "macros" with arguments

I have done some progressing myself too, if it is of any interest to you, I have fallen back to an old habit delayed expansion. I like your way of building the macro's. Can it work for my macros too or ? Is that not possible ? I'm not sure how to interpret your question. I am almost sure that there...
by dbenham
21 May 2011 17:14
Forum: DOS Batch Forum
Topic: New function - :hexDump
Replies: 10
Views: 13009

Re: New function - :hexDump

Up until now, all of my hexDump posts have relied on a "local" hexDump.addChar function that must be called for each character. This is a tremendous overhead. I remember wanting to embed the function code directly in the various loops, but the function was called 4 times, so I opted for im...