Killing command line FOR which runs a batfile?

May 20, 2008
11,400
99
Syracuse, NY, USA
Is there any way to abort a command line FOR command which runs a batch file? I
keep getting the "abort batch file" prompt and after answering "Y", the FOR loop
continues.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
On Mon, 02 Jun 2008 20:47:30 -0500, you wrote:


>vefatica wrote:
>
>
>---Quote---
>> Is there any way to abort a command line FOR command which runs a batch
>> file? I
>> keep getting the "abort batch file" prompt and after answering "Y", the
>> FOR loop continues.
>---End Quote---
>How are you trying to abort it?

With Ctrl-C/Ctrl-Break.
--
- Vince
 
May 20, 2008
11,400
99
Syracuse, NY, USA
vefatica wrote:
How are you trying to abort it?

Very occasionally (5th try, below), an "A" response to the "cancel batch" prompt works.

v:\> for /l %z in (1601,1,2008) agetodate.btm %@makeage[%z-02-28]
1601-02-28 00:00:00
[snip]
1644-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
1646-02-28 00:00:00
[snip]
1661-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
1663-02-28 00:00:00
[snip]
1675-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
1677-02-28 00:00:00
[snip]
1687-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
1689-02-28 00:00:00
[snip]
1698-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
v:\>

FINALLY!
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
vefatica wrote:

> Is there any way to abort a command line FOR command which runs a batch
> file? I
> keep getting the "abort batch file" prompt and after answering "Y", the
> FOR loop continues.

Can you give me the exact FOR syntax and batch file you're running?

I'm unable to reproduce the problem here with the FOR loop continuing.

Rex Conn
JP Software
 
May 20, 2008
11,400
99
Syracuse, NY, USA
vefatica wrote:
Can you give me the exact FOR syntax and batch file you're running?

I'm unable to reproduce the problem here with the FOR loop continuing.

I already gave the exact command. Here it is again.

v:\> for /l %z in (1601,1,2008) agetodate.btm %@makeage[%z-02-28]
1601-02-28 00:00:00
[snip]
1644-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
1646-02-28 00:00:00
[snip]
1661-02-28 00:00:00
^C

Cancel batch job V:\agetodate.btm ? (Y/N/A) : A
1663-02-28 00:00:00
[snip]
1675-02-28 00:00:00
^C
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
vefatica wrote:

>
> Quote:
> Originally Posted by *rconn* View Post <showthread.php?p=600#post600>
> vefatica wrote:
> Can you give me the exact FOR syntax and batch file you're running?
>
> I'm unable to reproduce the problem here with the FOR loop continuing.
>
> I already gave the exact command. Here it is again.
>
> v:\> for /l %z in (1601,1,2008) agetodate.btm %@makeage[%z-02-28]
> 1601-02-28 00:00:00
> [snip]
> 1644-02-28 00:00:00

You didn't provide the batch file contents.

Rex Conn
JP Software
 
May 20, 2008
11,400
99
Syracuse, NY, USA
You didn't provide the batch file contents.

> v:\> for /l %z in (1601,1,2008) agetodate.btm %@makeage[%z-02-28]
> 1601-02-28 00:00:00
> [snip]
> 1644-02-28 00:00:00

Actually I did post it in the Sparklist forum. I'm going to try to attach it (seems to have worked!). Just in case I'll paste it below. It's cryptic for speed.

I use a plugin @ISLEAP[] (=365|366). You'll need this:

function isleap=`%@if[%@eval[%1 %% 4] NE 0 .or. (%@eval[%1 %% 100] EQ 0 .and. %@eval[%1 %% 400] NE 0),365,366]`

::AGETODATE.BTM
setlocal
unset *
unalias *
unfunction *
set /a m=(%1 + 5000) \ 10000 & set /a d=%m \ 86400000 & set /a t=%m %% 86400000 & set /a s=%t \ 1000 & set /a t=%t %% 1000 & set y=1601
do while %d GE 146097
set /a y+=400 & set /a d-=146097
enddo
do i=1 to 3
iff %d GE 36524 then & set /a y+=100 & set /a d-=36524 & else & leave & endiff
enddo
do i=1 to 24
iff %d GE 1461 then & set /a y+=4 & set /a d-=1461 & else & leave & endiff
enddo
do i=1 to 3
iff %d GE 365 then & set /a y+=1 & set /a d-=365 & else & leave & endiff
enddo
set /a d+=1
set q=31 %@if[%@isleap[%y] EQ 365,28,29] 31 30 31 30 31 31 30 31 30 31
set m=0
do while %d GT %@word[%m,%q]
set /a d-=%@word[%m,%q] & set /a m+=1
enddo
echo %y-%@format[02,%@inc[%m]]-%@format[02,%d],%@maketime[%s].%@format[03,%t]
 

Attachments

  • agetodate.btm
    790 bytes · Views: 105

rconn

Administrator
Staff member
May 14, 2008
12,345
150
vefatica wrote:

>
> Quote:
> Originally Posted by *rconn* View Post <showthread.php?p=602#post602>
> You didn't provide the batch file contents.
>
> > v:\> for /l %z in (1601,1,2008) agetodate.btm %@makeage[%z-02-28]
> > 1601-02-28 00:00:00
> > [snip]
> > 1644-02-28 00:00:00
>
> Actually I did post it in the Sparklist forum. I'm going to try to
> attach it (seems to have worked!). Just in case I'll paste it below.
> It's cryptic for speed.
>
> I use a plugin @ISLEAP[] (=365|366). You'll need this:
>
> function isleap=`%@if[%@eval[%1 %% 4] NE 0 .or. (%@eval[%1 %% 100] EQ 0
> .and. %@eval[%1 %% 400] NE 0),365,366]`

WAD -- a Ctrl-C is *not* propagated back to parent commands. (Changing
this would be catastrophic for existing batch files and aliases!)

There is a special case when pressing a ^C in a batch file, in that you
are given the option of exiting the current batch file or all batch
files. However, it does *not* mean that the next command at the command
prompt will also be aborted.

After the ^C, the parser stops the batch file and returns to the FOR.
Since FOR doesn't (and shouldn't!) know that you pressed ^C, the only
thing it can do is check the return value of the batch file. Since you
didn't provide an ON BREAK, the return value is going to be the default (0).

If you want it to abort your FOR loop if you've aborted the at the
command prompt, you need to add something like this to the beginning of
the batch file:

on break quit 3

which will catch every ^C, return a 3 to the FOR, which will then abort
the loop. (FOR *always* aborts the loop if the target command returns a 3.)

Rex Conn
JP Software

p.s.: Your next question is going to be "Then why does it sometimes
break out of the FOR?" Because sometimes the ^C is during the batch
file initialization (or termination), so the ^C is sent to the current
command (which is the FOR).
 
May 20, 2008
11,400
99
Syracuse, NY, USA
On Wed, 04 Jun 2008 23:02:20 -0500, you wrote:


> on break quit 3
>
>which will catch every ^C, return a 3 to the FOR, which will then abort
>the loop. (FOR *always* aborts the loop if the target command returns a 3.)

Thanks!

That's very useful info, and an elegant solution. Is that well known? Is it
mentioned in the help (should be ... so simple and useful)?

--
- Vince
 
Similar threads
Thread starter Title Forum Replies Date
Dmitry L. Kobyakov How to? How to remove the record of the old version of the Take Command? Support 5
D Can alias pass parameters to for command? Support 3
samintz How to? Search for %(command) in Help? Support 1
T VIEW only works from command line Support 14
rconn News Take Command / TCC / CMDebug / TCC-RT v28 Released Support 0
T Take Command 28: Lua reports version 5.4.0 (5.4.3 expected) Support 0
Jay Sage WAD Possible Bug With OPTION Command With @FILE Support 5
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.24 uploaded Support 0
J Take command does not start on Windows 10 Support 3
vefatica `Back quotes` - command line vs. batch file Support 5
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
Phileosophos Is there any way to open the Take Command options dialog from the command line? Support 8
Phileosophos Command-line Editing Shortkeys That Fail Support 6
fpefpe How to? free (internal) command Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.23 uploaded Support 0
T How to? retain command history across reboot? Support 6
rconn News Take Command / TCC / CMDebug / TCC-RT v27.01 Build 22 Uploaded Support 0
Jay Sage Bug With Flow Control and/or Command Grouping Support 2
GermanDirk How to? EVENTLOG Command with simple User Rights not functional Support 4
Jay Sage Take Command Is Too Fast! Support 4
Jay Sage Comparison of IF with Command Group and IFF Support 6
D Open Windows 10 Photos app from command line Support 11
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.21 uploaded Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.20 uploaded Support 0
U Can not get/start Take Command gui Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.19 Support 0
S Increasing Font Point Size in Command Tabs Support 2
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica Command name mix-up Support 3
FreezerBurnt "Missing SETLOCAL" when initializing Visual Studio Command Prompt. Support 9
E How to? Closing desktop created by DESKTOP command Support 10
rconn News Take Command / TCC / CMDebug / TCC-RT v27.0.18 Support 0
K Take Command fox XP? Support 7
Joe Caverly Documentation Replace internal command with LIBRARY command Support 0
fpefpe How to? command echo in title line/bar Support 2
U Command help on file names Support 5
vefatica Command line DO with no closing parenthesis? Support 9
vefatica Command history search is off Support 7
H How to? How can I say "if the command separator is not ~ then setdos /C~" Support 8
N Command execution slows down in TCC Prompt after a while Support 6
R Long commands retrieved from command history have blank line when wrapped Support 20
jpeni Take Command Language Examples Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 26.02.41 Uploaded Support 0
fpefpe winfr command Support 4
Dmitry L. Kobyakov Fixed The SETARRAY /R command works incorrectly with cyrillic files Support 2
M Selecting test "off by one" problem in Take command Support 4
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
R How to? Open Take Command at current folder Support 7
rconn News Take Command / TCC / CMDebug / TCC-RT 26.01.40 uploaded Support 0
C TEE command appending null characters to output Support 6

Similar threads