Search found 35 matches
- 30 Sep 2022 04:48
- Forum: DOS Batch Forum
- Topic: [CLARIFIED] Executing command via FOR results in not recognized
- Replies: 4
- Views: 4318
Re: Executing command via FOR results in not recognized
It is the default behaviour: If you escape a character (using the circumflex-character '^'), or add characters when the interpreter expects text starting with escaped characters (using for-variables in the way you did), then it has no special function for the tokenizer that splits the command line ...
- 28 Sep 2022 07:50
- Forum: DOS Batch Forum
- Topic: [CLARIFIED] Executing command via FOR results in not recognized
- Replies: 4
- Views: 4318
Re: Executing command via FOR results in not recognized
That's not "nothing" - it's a space-character. Since the space-character is no valid command, the error message is correct. Typically space characters are treated as whitespace characters and will not end up beeing treated as a command. But you can force cmd to treat the space-character as a comman...
- 28 Sep 2022 05:25
- Forum: DOS Batch Forum
- Topic: [CLARIFIED] Executing command via FOR results in not recognized
- Replies: 4
- Views: 4318
[CLARIFIED] Executing command via FOR results in not recognized
This works as expected: for /f "tokens=1,* delims=," %b in ("call,dir") do %~b %~c Results: C:\Users\xxx>call dir Volume in drive C is System Volume Serial Number is 00E1-E8B3 Directory of... (dir listing) However, the following gives an error: for /f "tokens=1,* delims=," %b in (" ,dir") do %~b %~c...
- 16 Feb 2022 02:49
- Forum: DOS Batch Forum
- Topic: Recursively expand variables in strings
- Replies: 5
- Views: 6447
Re: Recursively expand variables in strings
Where an extra level of expansion is required, it is generally simpler to use call or a for loop to expand component delayed variables of macros. A short example of using call to trigger an extra parsing step for the sort of use case you propose: @Echo off For /f delims^= %%e in ('echo Prompt $E^|c...
- 14 Feb 2022 19:49
- Forum: DOS Batch Forum
- Topic: Recursively expand variables in strings
- Replies: 5
- Views: 6447
Re: Recursively expand variables in strings
Note: the double colon : character also interferes with expanding variables recursively the way the function does. So i recommended to replace them too in strings with for instance #dc# en substitute them with double colons in the return value when needed literally. To explain why I don't just simpl...
- 13 Feb 2022 22:57
- Forum: DOS Batch Forum
- Topic: Batch command
- Replies: 2
- Views: 4693
Re: Batch command
This would do the trick: @echo off pause for %%b in ("C:\Program Files (x86)\Symantec\Symantec Endpoint Protection") do ( start "Contents of Symantec Endpoint Protection" /wait "cmd" "/d /k dir /p /on "%%~sfb" & pause & exit ) pause exit /b Hang on, never mind, didn't read the post itself well and t...
- 13 Feb 2022 21:51
- Forum: DOS Batch Forum
- Topic: Recursively expand variables in strings
- Replies: 5
- Views: 6447
Re: Recursively expand variables in strings
Havn't found any solutions yet, so i recommended doing the same with ^ caret characters as with ! exclamation mark characters as i explained above. In the example below i replace #ct# with ^ in the returned result. Example: @echo off REM Code to test recursively expand variables in strings: set "tes...
- 13 Feb 2022 21:28
- Forum: DOS Batch Forum
- Topic: Recursively expand variables in strings
- Replies: 5
- Views: 6447
Re: Recursively expand variables in strings
Found a workaround at least for the mentioned issue about literally meant special characters ! and %. The updated function currently replaces #pc# with % percent sign characters. Function: :Expand Text [Rtn] :: @param (str) Text text with variables to expand :: @param (str) Rtn return variable :: @r...
- 13 Feb 2022 15:43
- Forum: DOS Batch Forum
- Topic: Recursively expand variables in strings
- Replies: 5
- Views: 6447
Recursively expand variables in strings
Hello everyone, I wanted to share a function i just made to recursively expand variables in strings. I've searched for it here and havn't come accross it on the forum so i thought to post it here. It works for me for most and simple cases, i hope it may be of help to others. Function to recursively ...
- 04 Feb 2022 06:19
- Forum: DOS Batch Forum
- Topic: Variable nesting, odd behavior maybe useful. Update: not new, already handled at DosTips
- Replies: 6
- Views: 6548
Re: Variable nesting, odd behavior maybe useful
Aahh thanks for the explanation clearing things up! :) I will look into those topics you mentioned for further information. Very interested in the use-case you mentioned sst. True these are not really nested variables, wanted a simple example to reproduce the behavior I encountered. Thanks again a l...
- 03 Feb 2022 17:40
- Forum: DOS Batch Forum
- Topic: Variable nesting, odd behavior maybe useful. Update: not new, already handled at DosTips
- Replies: 6
- Views: 6548
Re: Variable nesting, odd behavior maybe useful
If somehow cmd.exe can continue after ") is unexpected at this time" errors, then this behavior could be used and save a lot of code.
- 03 Feb 2022 17:36
- Forum: DOS Batch Forum
- Topic: Variable nesting, odd behavior maybe useful. Update: not new, already handled at DosTips
- Replies: 6
- Views: 6548
Re: Variable nesting, odd behavior maybe useful
Even simpler code to reproduce it: @echo off REM Case study: "variable refences variable references variable..." set "test1=a value 123" set "test2=!test1! 456" set "test3=!test2! 789" set "test4=!test3! 10" set "test5=!test4! 11" set "test6=!test5! 12" set "test7=!test6! 13" set "test8=!test7! 14" ...
- 03 Feb 2022 15:50
- Forum: DOS Batch Forum
- Topic: Variable nesting, odd behavior maybe useful. Update: not new, already handled at DosTips
- Replies: 6
- Views: 6548
Re: Variable nesting, odd behavior maybe useful
Smaller code sample to reproduce effect: @echo off REM Case study: "variable refences variables references variable..." set "test1=a value 123" set "test2=!test1! 456" set "test3=!test2! 789" set "test4=!test3! 10" set "test5=!test4! 11" set "test6=!test5! 12" set "test7=!test6! 13" set "test8=!test...
- 03 Feb 2022 15:34
- Forum: DOS Batch Forum
- Topic: Variable nesting, odd behavior maybe useful. Update: not new, already handled at DosTips
- Replies: 6
- Views: 6548
Variable nesting, odd behavior maybe useful. Update: not new, already handled at DosTips
I wanted a routine for expanding nested variables no matter how many levels deep. I was fiddling with dynamically constructing FOR statements for each nested level to expand nested variables when i stumbled upon some interesting behavior, and an error but that was expected and easily resolved. Below...
- 22 Apr 2021 04:12
- Forum: DOS Batch Forum
- Topic: Delete specified multiple lines of a not in use batch file through another batch file?
- Replies: 4
- Views: 6601
Re: Delete specified multiple lines of a not in use batch file through another batch file?
I'd suggest to keep your original post original and place updates in a reply/comment. Otherwise, people might get confused about the article. Just a friendly tip :wink: Based on your current update of this article, I've created and tested some code. Below I've adjusted your code a bit to make it wor...