Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Abort on error DO loop

samintz

Scott Mintz
May
1,590
27
If I have a command line DO that is operating on a list is it possible to abort the DO if the command errors?
E.g.
Code:
do f in /l a b c (somecommand %f)

If somecommand errors while working on a or b, I'd like the DO to stop and not even try c.
 
Does 'somecommand' return a nonzero exit code when it fails?
That doesn't seem to matter (see below). I thought maybe you could do it manually by looking at _DO_ERRORS, but no. What kind of errors does _DO_ERRORS count?

Code:
v:\> do z in /L xx yy ( dir %z & echo %_? %_do_errors)

 Volume in drive V is DATA         Serial number is 6e8a:6d1f
TCC: (Sys) The system cannot find the file specified.
 "V:\xx"
                   0 bytes in 0 files and 0 dirs
     492,625,555,456 bytes free
2 0

 Volume in drive V is DATA         Serial number is 6e8a:6d1f
TCC: (Sys) The system cannot find the file specified.
 "V:\yy"
                   0 bytes in 0 files and 0 dirs
     492,625,555,456 bytes free
2 0

You can force it:

Code:
v:\> do z in /L xx yy ( dir %z & if %_? != 0 leave )

 Volume in drive V is DATA         Serial number is 6e8a:6d1f
TCC: (Sys) The system cannot find the file specified.
 "V:\xx"
                   0 bytes in 0 files and 0 dirs
     492,625,555,456 bytes free

v:\> do z in /L xx yy ( grep foo %z & if %? != 0 leave )
grep: xx: No such file or directory

v:\>
 
Or, a bit shorter, do z in /L xx yy ( dir %z || leave )
Yeah! I like that.

I can't get _DO_ERRORS to be other than 0. Anyone else?

Charles, what's "icode" (something new)? It looks nice in your post and not so nice when I quote you.
 
OK, found it (icode). It looks OK after I post. Quoting your icode didn't look good in the editor.
 
Back
Top
[FOX] Ultimate Translator
Translate