Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#1
Post
by Ed Dyreen » 12 Nov 2011 10:21
'
currently I use this overflow technique to set the errorlevel, I wonder whether it can be shortened:
Code: Select all
>nul 2>&1 ( if !$error! neq 0 ( set /a $? = 0 ) else set /a $? = 9999999999 )
It can only switch the errorlevel between 1 and 0, I wonder if it's possible to change that, like u can do at the end of a function

I use it for chaining macro's:
Code: Select all
>nul 2>&1 ( if !$error! neq 0 ( set /a $? = 0 ) else set /a $? = 9999999999 ) &&echo.yes ||echo.no !errorlevel!
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#3
Post
by Ed Dyreen » 12 Nov 2011 10:28
'
isn't that like very slow ?, it's definetly short, I think I'll take it

-
aGerman
- Expert
- Posts: 4736
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 12 Nov 2011 10:36
It takes some time to load another instance of cmd.exe. How fast it is depends on your machine.
Regards
aGerman
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#5
Post
by Ed Dyreen » 12 Nov 2011 10:40
'
How beautifull, thanks A

, where is my creativity ?
Code: Select all
C:\PROFSYS\ADMIN>cmd /c exit 1 ||echo.not
not
C:\PROFSYS\ADMIN>cmd /c exit 0 &&echo.odd ||echo.not
odd