Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
MLGsuperGame414
- Posts: 54
- Joined: 10 Nov 2011 20:40
#1
Post
by MLGsuperGame414 » 14 Nov 2011 20:24
Okay this time I have a few questions.
How to make your batch file search for a line of code within it selfBy this I am asking how you can have your batch file search itself for a line of code. Specifically for finding errors. Mainly because I just am not really understanding the whole error levels stuff. And therefore if there is a problem I can have my program echo the line of code where it went wrong.
Next
Can you use If, than, and Else.I have tried to use this command a few times in a batch file I am working on but it never seems to work. I use it in C++ and BASIC and I though you could use it in BATCH but I can't seem to get it to work. Here is an example of code in which I try to use it.
Code: Select all
if "%cs%"=="19" %USERDOMAIN%
if "%cs%"=="20" %USERNAME% else Echo Invalid Choice.
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#2
Post
by Ed Dyreen » 15 Nov 2011 04:09
'
That's weird, it works perfectly over here:
Code: Select all
set /a $val = 1
if defined $val (
echo. defined
if %$val% equ +%val% (
echo.int
if %$val% gtr 0 (
echo.whole number
if $val lss 1000 (
echo.small number
) else echo.big number
) else echo.natural number
) else echo.no int
) else echo.undefined
echo the line that went wrong, hmm that's a bit difficult, I used to use %CMDCMDLINE% for that, but under XP it holds the last batch parameters and not the last executed command, yes you can go looking for that line, it's not easy though.
First of all you would have to get the line number, or some other id...