Search found 44 matches

by sincos2007
03 Jun 2019 06:34
Forum: DOS Batch Forum
Topic: How to get parameters of script in subroutine
Replies: 2
Views: 2615

How to get parameters of script in subroutine

command line:

Code: Select all

abc.bat -i valOfI -o valOfO
In abc.bat, define a subroutine func1. In func1, get valOfI and valOfO from command line. Order of “-i valOfI” and “-o valOfO” can be any in command line.

Thanks
by sincos2007
01 Jun 2019 14:31
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

Re: why does this code output such result

Very appreciate for your help and patience. Your explanation is valuable and rare. Very clear and helpful and into detail. Hope this could help others.

Thanks.
by sincos2007
01 Jun 2019 01:54
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

Re: why does this code output such result

Sorry, I have not state my question in accuracy. This is another question. I want to know why following two commands have different output: echo " %str1% echo %str1% if definition of str1 is: set str1="a^!bcd^!efg^^^^^^^^^^^!^^^^^^^!^^^^^^^^^^!hi^^^^^^^^^!^^^^!^!" or if definition of str1 after remo...
by sincos2007
31 May 2019 03:57
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

Re: why does this code output such result

I do not understand clearly from your explanation why code:

Code: Select all

echo “ %str1%
need phase 2, but code:

Code: Select all

echo %str1%
does not.

output of code: echo %str1%

Code: Select all

"aefg^^^^^^escapeOnly "
thanks
by sincos2007
30 May 2019 03:13
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

Re: why does this code output such result

Is it because third exclamation mark is escaped and lost its special meaning, so it and fourth exclamation mark cannot be used to expand variable?
by sincos2007
29 May 2019 22:19
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

Re: why does this code output such result

Hi Dave,

Thank you for your help. The content is very detailed.

One question: after phase 2, why third ! and ^^ and fourth ! does not expand to value of variable ^^, but only stripe fourth ! .

thanks
by sincos2007
29 May 2019 06:05
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

Re: why does this code output such result

look at this link: viewtopic.php?f=3&t=9137

I want to research how the example in link above works when I assign const string to variable str1

thanks
by sincos2007
28 May 2019 15:43
Forum: DOS Batch Forum
Topic: why does this code output such result
Replies: 11
Views: 2451

why does this code output such result

code: set "^=escapeOnly" set hi=hi001 set str1="a^!bcd^!efg^^^^^^^^^^^^^!^^^^^^^^^^^!^^^^^^^^^^!hi^^^^^^^^^!^^^^!^!" echo ----- original ---- echo !str1! echo ----- other 4 ----- 2x echo " %str1% output: ----- original ---- "a!bcd!efg^^^^^^!^^^^^!^^^^^^^escapeOnly " ----- other 4 ----- 2x " "aefg^!^...
by sincos2007
15 May 2019 22:10
Forum: DOS Batch Forum
Topic: what regular of conversion of special characters under enable delayed expansion is
Replies: 2
Views: 631

Re: what regular of conversion of special characters under enable delayed expansion is

In ‘other 2’ in your code, can I understand in this way:

1. remove all caret
2. collapse all consecutive opening exclamation mark into one
3. expand variable between two exclamation marks from left to right
by sincos2007
11 May 2019 14:41
Forum: DOS Batch Forum
Topic: what regular of conversion of special characters under enable delayed expansion is
Replies: 2
Views: 631

what regular of conversion of special characters under enable delayed expansion is

code: :test1 setlocal EnableDelayedExpansion set "filename=temp1.txt" set "str1=" & <"%filename%" set /p "str1=" echo output 1 set str1 echo !str1! echo %str1% echo output 2 set "str2=%str1%" set str2 echo !str2! echo %str2% endlocal goto :eof content of temp1.txt abc %%var1%% ^!^!var2^!^! mmm !var3...
by sincos2007
07 May 2019 13:55
Forum: DOS Batch Forum
Topic: Is it possible to pull variable out of setlocal and endlocal pair in for loop
Replies: 1
Views: 1403

Is it possible to pull variable out of setlocal and endlocal pair in for loop

:test5 setlocal DisableDelayedExpansion set /a "n=0" for /f "delims=" %%i in (txt1.txt) do ( set "line=%%i" setlocal EnableDelayedExpansion set "str_out=!str_out! / number{!n!}-{!line!}" rem debug echo !str_out! endlocal&set "str_out_1=%str_out%" set /a "n+=1" echo Position 1: echo str_out_1=%str_o...
by sincos2007
04 May 2019 00:56
Forum: DOS Batch Forum
Topic: How to preserve exact number of space characters after split by for
Replies: 2
Views: 610

How to preserve exact number of space characters after split by for

:test2 setlocal DisableDelayedExpansion set "line1= abc # %%var1%% # ^!var2^!" for /f "usebackq delims=# tokens=1,2,3*" %%i in ('%line1%') do ( echo {%%i} echo {%%j} echo {%%k} ) endlocal goto :eof There are 3 space characters at both sides of “abc” in variable line1. But after I split line1 by for...
by sincos2007
01 May 2019 09:27
Forum: DOS Batch Forum
Topic: how to read line in text file and return it by function
Replies: 5
Views: 699

Re: how to read line in text file and return it by function

Hi Steffen,

In your code, if add “setlocal EnableDelayedExpansion” to beginning of function test6 and “endlocal” at end of test6, how could you make it work?

Thanks
by sincos2007
01 May 2019 04:34
Forum: DOS Batch Forum
Topic: how to read line in text file and return it by function
Replies: 5
Views: 699

Re: how to read line in text file and return it by function

Hi Steffen, Look following code: :test6 setlocal EnableDelayedExpansion set "lines_cnt=2" set "in_file=temp.txt" set "line=" set /a "n=0" <"!in_file!" ( for /l %%j in (1 1 !lines_cnt!) do ( set "line=" &set /p "line=" if defined _ret ( set "_ret=!_ret!^&" ) set "_ret=!_ret!set %~1[!n!]=!line! set /a...