NOP+nested code.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

NOP+nested code.

#1 Post by einstein1969 » 14 Mar 2014 11:37

Hi to all,

I have problem with this code:

Code: Select all

@echo off & setlocal

rem first:
cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if not "!time:~9,2!"=="99" (if not "!time:~9,2!"=="00" (break) else exit) else exit" & echo ok

echo %time%

rem second:
start "" /B cmd /V:ON /Q /C"cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if not "!time:~9,2!"=="99" (if not "!time:~9,2!"=="00" (break) else exit) else exit" & echo ok"



I have two question:

1) The "first" part work well but the "second" part don't work (go in loop).
How to modify code for working the second part?

2) NOP: I searching for NO Operation. I have used "break".
There are other NOP?

einstein1969

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: NOP+nested code.

#2 Post by Ed Dyreen » 14 Mar 2014 13:20

why not reverse the if condition ?

Code: Select all

if "!time:~9,2!"=="00" exit
or even

Code: Select all

if "!time:~9,2!"=="00" (exit) else rem.this does nothing
instead of

Code: Select all

if not "!time:~9,2!"=="00" (break) else exit
I assume that if 1==0 equals break ? Why not use rem. ?

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: NOP+nested code.

#3 Post by einstein1969 » 14 Mar 2014 14:35

Hi Ed,

thanks , i have optimized the code

Code: Select all

cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit) else rem.this does nothing)" & echo ok

echo %time%

cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit))" & echo ok

echo %time%


start "" /B cmd /V:ON /Q /C"cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit))" & echo ok"


generally (in code more complex ) I don't use the REM because with the REM ignores all the rest of the line.

The first and the second work well.
The third go in loop :?

einstein1969

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: NOP+nested code.

#4 Post by Ed Dyreen » 14 Mar 2014 15:43

einstein1969 wrote:Hi Ed,

thanks , i have optimized the code

Code: Select all

cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit) else rem.this does nothing)" & echo ok

echo %time%

cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit))" & echo ok

echo %time%


start "" /B cmd /V:ON /Q /C"cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit))" & echo ok"


generally (in code more complex ) I don't use the REM because with the REM ignores all the rest of the line.
You can insert a "delayed" linefeed to counter that.

Code: Select all

@echo off &setlocal enableDelayedExpansion
set $lf=^


::
set ^"$n1c=^^^%$lf%%$lf%^%$lf%%$lf%^^"

set ^"macro=(^

   echo ok0%$n1c%

   for /L %%k in (1,0,1) do if "^!time:~9,2^!"=="99" (^

      exit^

   ) else if "^!time:~9,2^!"=="00" (^

      exit^

   ) else rem.this does nothing%$n1c%

   echo ok1%$n1c%
)"

set "macro"

%=                  inject delay once   =%
set "?=!macro!"
for %%r in ("!$lf!") do for %%? in ("%%$lf%%") do set ?=!?:%%~r=%%~?!
set "macro=!?!"

set "macro"

cmd /v:on /e:on /t:0B /q /c "!macro!"

pause
exit /b

Code: Select all

macro=(
        echo ok0

        for /L %k in (1,0,1) do if "!time:~9,2!"=="99" (
                exit
        ) else if "!time:~9,2!"=="00" (
                exit
        ) else rem.this does nothing

        echo ok1
)
macro=(%$lf%    echo ok0%$lf%%$lf%      for /L %k in (1,0,1) do if "!time:~9,2!"
=="99" (%$lf%           exit%$lf%       ) else if "!time:~9,2!"=="00" (%$lf%
        exit%$lf%       ) else rem.this does nothing%$lf%%$lf%  echo ok1%$lf%)
ok0
Druk op een toets om door te gaan. . .
einstein1969 wrote:

Code: Select all

start "" /B cmd /V:ON /Q /C"cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit))" & echo ok"


generally (in code more complex ) I don't use the REM because with the REM ignores all the rest of the line.

The first and the second work well.
The third go in loop :?
In the third example you start cmd twice with v:on, now you need to escape once more so the time is updated in realtime

Code: Select all

@echo off

start "" /B cmd /V:ON /Q /C "cmd /V:ON /Q /C^"for /L %%k in (1,0,1) do echo.if "^!time:~9,2^!"=="99" echo ok"

pause
exit /b

Code: Select all

if "54"=="99 echo ok
if "54"=="99 echo ok
if "56"=="99 echo ok
if "56"=="99 echo ok
etc...

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: NOP+nested code.

#5 Post by penpen » 14 Mar 2014 17:06

einstein1969 wrote:I don't use the REM because with the REM ignores all the rest of the line

You may add a double colon to rem, so the special keys are working, and the rest of the line should not be ignored anymore:

Code: Select all

if 0==0 (rem:) else echo 1
if 0==1 (rem:) else echo 0

penpen

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: NOP+nested code.

#6 Post by Liviu » 15 Mar 2014 00:43

penpen wrote:You may add a double colon to rem, so the special keys are working, and the rest of the line should not be ignored anymore:

Code: Select all

if 0==0 (rem:) else echo 1
if 0==1 (rem:) else echo 0

Not sure what you mean by "so the special keys are working" but the (rem:) trick is neat regardless ;-)

Still, it's not a no-op technically. If you watch cmd.exe with sysinternals' Process Monitor you'll notice that typing "rem:" at the cmd prompt causes a file-system-level inquiry for "rem:" (FastIoQueryOpen) which does not occur for a plain "rem" without the ":" colon. The "rem:" inquiry fails because of "invalid name", and I guess that's caught early - before and without any disk access. And it appears that cmd decides to do nothing about the reported failure, so it works out as a no-op in the end, but - again, strictly technically - it's not as if cmd translated it into a NOP upfront.

Liviu

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: NOP+nested code.

#7 Post by Ed Dyreen » 15 Mar 2014 16:39

einstein1969 wrote:I don't use the REM because with the REM ignores all the rest of the line.
And if not, the worst thing that can happen is it causing your script to crash :P

Code: Select all

@echo off

REM does not ignores all the rest of the line. %~*
REM.does not ignores all the rest of the line. %~*

Code: Select all

Het volgende gebruik van de padoperator bij het vervangen
van batchparameters is ongeldig: %~*


Typ CALL /? of FOR /? voor geldige gebruiksmogelijkheden.
De syntaxis van de opdracht is onjuist.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: NOP+nested code.

#8 Post by einstein1969 » 15 Mar 2014 20:09

Ed Dyreen wrote:
einstein1969 wrote:I don't use the REM because with the REM ignores all the rest of the line.
And if not, the worst thing that can happen is it causing your script to crash :P

Code: Select all

@echo off

REM does not ignores all the rest of the line. %~*
REM.does not ignores all the rest of the line. %~*

Code: Select all

Het volgende gebruik van de padoperator bij het vervangen
van batchparameters is ongeldig: %~*


Typ CALL /? of FOR /? voor geldige gebruiksmogelijkheden.
De syntaxis van de opdracht is onjuist.


I did not know this thing :evil:
I am studying the macro you posted previously ... :shock:

@penpen
I will remember in future. and ...

@Liviu
I have done some tests


The code that i using is in a PIPED code.
I have tested and there is a problem with the SPACES added

There are workaround for the spaces?

Code: Select all

@echo off & setlocal

cls

:: Setting
set /a max_loops=1000*4*20
set "LOG=nop.log.txt"
set "FILE=temp.$$$"
set list="type nul" "rem:" "break" "call" "call " "title" "echo/>nul"

:: clear LOG
break > %LOG%

:: Do Testing
for %%N in (%list%) do call :NOP %%N

:: Print Performance results
echo/
Echo           NOP   Loops   Elapsed[cs]   Avg[microsec]   Type
echo -----------------------------------------------------------------------
for %%N in (%list%) do (
  Echo/
  set H=%%~N____
  set "d=           %%N"
  for %%T in (NO_PIPE PIPE CLEAR) do (
    call set HH=%%H::=%%
    call set HH=%%HH:~0,5%%_%%T
    for /f "tokens=1-3 delims=;" %%f in ('call echo %%%%HH%%%%') do call echo %%d:~-14%%   %%h   %%f      %%g      [%%T]
  )

)

:: Show the LOG
start notepad %LOG%

exit /b


:Nop

set "NOP=%~1"

if "%NOP%"=="echo/>nul" set /a max_loops*=10

set t0=%time%

:: TEST with no PIPE
For /L %%n in (1,1,%max_loops%) do (
 %NOP%
 (if %%n == 1 (
   echo/
   echo Testing... NOP:'%NOP:>=%' [NO_PIPE]
  )
 )
 %NOP%
)

call :time "%t0%" "%time%" NO_PIPE

:: test clear file

set /a max_loops/=4

del %FILE% 2>nul

set t0=%time%

:: TEST with no PIPE
For /L %%n in (1,1,%max_loops%) do (
 %NOP%>%FILE%
 (if %%n == 1 (
   echo Testing... NOP:'%NOP:>=%' [clear file]
  )
 )
)

call :time "%t0%" "%time%" CLEAR

if not exist %FILE% echo FILE ERROR!

set /a max_loops*=4

if "%NOP%"=="title" set /a max_loops/=20

set t0=%time%

:: TEST with PIPE
break| For /L %%n in (1,1,1000000) do @(
 %NOP%
 (if %%n==%max_loops% (exit))

 (if %%n == 1 (
   echo Testing... NOP:'%NOP:>=%' [PIPE]
   ( echo Testing... NOP:'%NOP:>=%' [PIPE]
     echo/
     echo cmdcmdline: %%cmdcmdline%%
   ) >> %LOG%
  )
 )
 %NOP%
)

call :time "%t0%" "%time%" PIPE

:: Check %errorlevel%
(%NOP%)

(
  echo/
  echo NOP:'%NOP%' Errorlevel:%errorlevel%
  echo/
) >> %LOG%

exit /b

:time

set "t=%~1:%~2"
For /F "tokens=1-8 delims=:.," %%a in ("%t: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, avg=a*10000/max_loops"

set H=%NOP::=%____
rem echo %H% %H:~0,5%_%3=%a%;%avg%;%max_loops%

set %H:~0,5%_%3=%a%;%avg%;%max_loops%

exit /b


results:

Code: Select all


Testing... NOP:'type nul' [NO_PIPE]
Testing... NOP:'type nul' [clear file]
Testing... NOP:'type nul' [PIPE]

Testing... NOP:'rem:' [NO_PIPE]
Testing... NOP:'rem:' [clear file]
Testing... NOP:'rem:' [PIPE]

Testing... NOP:'break' [NO_PIPE]
Testing... NOP:'break' [clear file]
Testing... NOP:'break' [PIPE]

Testing... NOP:'call' [NO_PIPE]
Testing... NOP:'call' [clear file]
Testing... NOP:'call' [PIPE]

Testing... NOP:'call ' [NO_PIPE]
Testing... NOP:'call ' [clear file]
Testing... NOP:'call ' [PIPE]

Testing... NOP:'title' [NO_PIPE]
Testing... NOP:'title' [clear file]
Testing... NOP:'title' [PIPE]

Testing... NOP:'echo/nul' [NO_PIPE]
Testing... NOP:'echo/nul' [clear file]
Testing... NOP:'echo/nul' [PIPE]

          NOP   Loops   Elapsed[cs]     Avg[microsec]   Type
-----------------------------------------------------------------------

    "type nul"  80000   903             112             [NO_PIPE]
    "type nul"  80000   1112            139             [PIPE]
    "type nul"  20000   652             326             [CLEAR]

        "rem:"  80000   613             76              [NO_PIPE]
        "rem:"  80000   794             99              [PIPE]
        "rem:"  20000   582             291             [CLEAR]

       "break"  80000   328             41              [NO_PIPE]
       "break"  80000   515             64              [PIPE]
       "break"  20000   535             267             [CLEAR]

        "call"  80000   302             37              [NO_PIPE]
        "call"  80000   597             74              [PIPE]
        "call"  20000   570             285             [CLEAR]

       "call "  80000   450             56              [NO_PIPE]
       "call "  80000   609             76              [PIPE]
       "call "  20000   578             289             [CLEAR]

       "title"  80000   489             61              [NO_PIPE]
       "title"  4000    922             2305            [PIPE]
       "title"  20000   561             280             [CLEAR]

   "echo/>nul"  40000   1034            258             [NO_PIPE]
   "echo/>nul"  40000   1156            289             [PIPE]
   "echo/>nul"  10000   373             373             [CLEAR]


LOG:

Code: Select all

Testing... NOP:'type nul' [PIPE] 
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( type nul & ( if 1== 80000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'type nul' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'type nul' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & type nul ) "

NOP:'type nul' Errorlevel:0

Testing... NOP:'rem:' [PIPE]
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( rem: & ( if 1== 80000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'rem:' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'rem:' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & rem: ) "

NOP:'rem:' Errorlevel:0

Testing... NOP:'break' [PIPE]
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( break & ( if 1== 80000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'break' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'break' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & break ) "

NOP:'break' Errorlevel:0

Testing... NOP:'call' [PIPE]
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( call & ( if 1== 80000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'call' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'call' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & call ) "

NOP:'call' Errorlevel:1

Testing... NOP:'call ' [PIPE]
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( call & ( if 1== 80000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'call ' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'call ' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & call ) "

NOP:'call ' Errorlevel:0

Testing... NOP:'title' [PIPE]
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( title & ( if 1== 4000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'title' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'title' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & title ) "

NOP:'title' Errorlevel:0

Testing... NOP:'echo/nul' [PIPE]
 
cmdcmdline: C:\Windows\system32\cmd.exe  /S /D /c" FOR /L 1 in (1 1 1000000) do @ ( echo/ 1>nul & ( if 1== 40000 ( exit ) ) & ( if 1== 1 ( echo Testing... NOP:'echo/nul' [PIPE] & 1>>nop.log.txt ( echo Testing... NOP:'echo/nul' [PIPE] & echo/ & echo cmdcmdline: %cmdcmdline% ) ) ) & echo/ 1>nul ) "



The title command in Piped version is slow because there are space added i thinks.


EDIT: correct some bugs + added timing for touch/clear a file.

einstein1969

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: NOP+nested code.

#9 Post by einstein1969 » 16 Mar 2014 11:29

Ed Dyreen wrote:In the third example you start cmd twice with v:on, now you need to escape once more so the time is updated in realtime

Code: Select all

@echo off

start "" /B cmd /V:ON /Q /C "cmd /V:ON /Q /C^"for /L %%k in (1,0,1) do echo.if "^!time:~9,2^!"=="99" echo ok"

pause
exit /b

Code: Select all

if "54"=="99 echo ok
if "54"=="99 echo ok
if "56"=="99 echo ok
if "56"=="99 echo ok
etc...


I have started from this:

original:

Code: Select all

start "" /B /WAIT cmd /V:ON /Q /C"cmd /V:ON /Q /C"for /L %%k in (1,0,1) do if "!time:~9,2!"=="99" (exit) else (if "!time:~9,2!"=="00" (exit))" & echo ok"


than i have added the caret ^
first mod:

Code: Select all

start "" /B /WAIT cmd /V:ON /Q /C"cmd /V:ON /Q /C^"for /L %%k in (1,0,1) do if "^!time:~9,2^!"=="99" (exit) else (if "^!time:~9,2^!"=="00" (exit))" & echo %%time%% %time% !time! ok"


but execute the echo in the nested cmd :?

than I have tried and the code work after adding a second " near the end

second mod:

Code: Select all

start "" /B /WAIT cmd /V:ON /Q /C"cmd /V:ON /Q /C^"for /L %%k in (1,0,1) do if "^!time:~9,2^!"=="99" (exit) else (if "^!time:~9,2^!"=="00" (exit))"" & call echo %%time%% %time% !time! ok"


result:

Code: Select all

18:13:22,99 18:13:21,99 !time! ok"


but i think that is no good because i need using "call echo". And there is an " at the end.

I want that the nested cmd exit and than "echo" run without "call".

What should I change? :?

einstein1969

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: NOP+nested code.

#10 Post by Ed Dyreen » 16 Mar 2014 12:37

einstein1969 wrote:second mod:

Code: Select all

start "" /B /WAIT cmd /V:ON /Q /C"cmd /V:ON /Q /C^"for /L %%k in (1,0,1) do if "^!time:~9,2^!"=="99" (exit) else (if "^!time:~9,2^!"=="00" (exit))"" & call echo %%time%% %time% !time! ok"
result:

Code: Select all

18:13:22,99 18:13:21,99 !time! ok"


but i think that is no good because i need using "call echo". And there is an " at the end.

I want that the nested cmd exit and than "echo" run without "call".

What should I change? :?
Since you appended to the command it works in that

Code: Select all

call echo %%time%% %time% !time! ok
the time the command is executed is displayed "echo %time%".
the time the command is finished is displayed "call echo %%time%%".
but this obviously doesn't "!time!" as you forgot to enable delayed expansion

Code: Select all

@echo off

echo.time.str=%time%_
cmd /V:ON /Q /C^"^
   for /L %%k in (^
      1,0,1^
   ) do if "!time:~9,2!"=="99" (^
      exit^
   )else if "!time:~9,2!"=="00" (^
      exit^
   )^
"
echo.time.end=%time%_

pause
exit /b

Code: Select all

time.str=19:35:25,28_
time.end=19:35:26,00_
Druk op een toets om door te gaan. . .
einstein1969 wrote:And there is an " at the end.
If you count the quotes you see that you add a double quote at the end of the line but your command inside a child cmd session is already complete
Code: wrote:start "" /B /WAIT cmd /V:ON /Q /C"cmd /V:ON /Q /C^"for /L %%k in (1,0,1) do if "^!time:~9,2^!"=="99" (exit) else (if "^!time:~9,2^!"=="00" (exit))"" & call echo %%time%% %time% !time! ok"
This works since the previous quote is consumed by the child session.

Code: Select all

@echo off

cmd /V:ON /Q /C"cmd /V:ON /Q /C^"echo.^>nul"" & call echo %%time%% %time% !time! ok"
cmd /V:ON /Q /C"cmd /V:ON /Q /Cecho.a!^>nul" &echo.b! &call echo %%time%% %time% !time! ok"
pause
exit /b

Code: Select all

19:48:54,75 19:48:54,64 !time! ok"
b!
19:48:54,87 19:48:54,75 !time! ok"
Btw;

Code: Select all

cmd /V:ON /Q /C"cmd /V:ON /Q /C
What is the point of running a cmd session inside a cmd session ? :?

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: NOP+nested code.

#11 Post by einstein1969 » 16 Mar 2014 12:49

the code is inside another code. I need to run async.

the code i more complex. This is only a part.
This is the old code that not work:

Code: Select all

(
  For /L %%i in (1,1,10) do @(
   start "" /B cmd /V:ON /Q /C"( break|for /L %%k in (1,0,1) do if not "!time:~9,2!"=="99" (if not "!time:~9,2!"=="00" (break) else (exit /b 1) ) else (exit /b 1) ) & (ping ::1 -n 5 -l 1)"
   ping ::1 -n 2 >nul
   For /L %%j in (0,1,1000) do @break
  )
) | find "<" | ...


einstein1969

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: NOP+nested code.

#12 Post by Ed Dyreen » 16 Mar 2014 13:07

I see,

One other thing, don't these long lines read much easier with line breaks ?

Code: Select all

@echo off

echo.time.str=%time%_
cmd /V:ON /Q /C^"^
   for /L %%k in (^
      1,0,1^
   ) do if "!time:~9,2!"=="99" (^
      exit^
   )else if "!time:~9,2!"=="00" (^
      exit^
   )^
"
echo.time.end=%time%_

pause
exit /b
You make it difficult to keep track of quoted status and general understanding. Even you got confused just previously.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: NOP+nested code.

#13 Post by einstein1969 » 16 Mar 2014 14:21

Ed Dyreen wrote:I see,

One other thing, don't these long lines read much easier with line breaks ?

Code: Select all

@echo off

echo.time.str=%time%_
cmd /V:ON /Q /C^"^
   for /L %%k in (^
      1,0,1^
   ) do if "!time:~9,2!"=="99" (^
      exit^
   )else if "!time:~9,2!"=="00" (^
      exit^
   )^
"
echo.time.end=%time%_

pause
exit /b
You make it difficult to keep track of quoted status and general understanding. Even you got confused just previously.


Thanks,

this is better.

Now i want to start async with start

I have insert in the code:

Code: Select all

(
  For /L %%i in (1,1,10) do @(


:: this part need start aync. The output need go to pipe with FIND "<". I think to use START.
echo.time.str=%time%_
cmd /V:ON /Q /C^"^
   for /L %%k in (^
      1,0,1^
   ) do if "!time:~9,2!"=="99" (^
      exit^
   )else if "!time:~9,2!"=="00" (^
      exit^
   )^
"
echo.time.end=%time%_
ping ::1 -n 5
:: here finish the part to start async

 
   ping ::1 -n 2 >nul
   For /L %%j in (0,1,1000) do @break
  )
) | find "<"


but already it does not work:

Code: Select all

do non atteso.


einstein1969

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: NOP+nested code.

#14 Post by Ed Dyreen » 16 Mar 2014 15:48

If a double colon is used inside a code block then a special rule applies.

Code: Select all

(
:: here you crash your script
)
It must be followed by a valid command or it crash your script.

Code: Select all

(
:: this works, the double colon is followed by a valid command
rem
)

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: NOP+nested code.

#15 Post by einstein1969 » 16 Mar 2014 15:58

Ed Dyreen wrote:If a double colon is used inside a code block then a special rule applies.

Code: Select all

(
:: here you crash your script
)
It must be followed by a valid command or it crash your script.

Code: Select all

(
:: this works, the double colon is followed by a valid command
rem
)


thanks,

i have removed the comment but the problem remain: :(

Code: Select all

(
  For /L %%i in (1,1,10) do @(


echo.time.str=%time%_
cmd /V:ON /Q /C^"^
   for /L %%k in (^
      1,0,1^
   ) do if "!time:~9,2!"=="99" (^
      exit^
   )else if "!time:~9,2!"=="00" (^
      exit^
   )^
"
echo.time.end=%time%_
ping ::1 -n 5

 
   ping ::1 -n 2 >nul
   For /L %%j in (0,1,1000) do @break
  )
) | find "<"


einstein1969

Post Reply