Batch DEBUG

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Batch DEBUG

#1 Post by einstein1969 » 13 Apr 2014 06:40

Hi to all,

Very often I get the message: The syntax of the command is incorrect.

Code: Select all

Sintassi del comando errata.
E:\x264\provini>


Someone has implemented a mechanism to automatically get the line where it occurred or checkpoints or other?

Thanks

einstein1969

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

Re: Batch DEBUG

#2 Post by einstein1969 » 13 Apr 2014 07:43

There is a method for get execute at the parser another code?

I look that it is possible catch a line number in this mode, but i don't know if it is usefull

Code: Select all

@echo off & setlocal EnableDelayedExpansion

if NOT "%1"=="" goto %1

:: Create the file with line number

:: Add at every line a code that...

For /f %%e in ('%~nx0 Debug 2^>^&1') do (
   set mess=%%e
   if /I "!mess:~0,3!"=="REM" echo Stop at !mess:*.=! 1>&2
)

goto :eof

:Debug
 rem.1  @echo off      &:
 rem.2  echo prova      &:
 rem.3k echo yyyyy      &:


Note: the last line don't have CR/LF

output

Code: Select all

E:\x264\provini>debug_batch.cmd
Stop at 3k


einstein1969
Last edited by einstein1969 on 13 Apr 2014 07:59, edited 2 times in total.

aGerman
Expert
Posts: 4745
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch DEBUG

#3 Post by aGerman » 13 Apr 2014 07:46

The only debugger that I know is cmd.exe :wink: Open the Batch file within a separate cmd shell. With ECHO ON you can easily find out where a command fails unless one of the command lines in a block enclosed into parentheses caused a problem. In this case the error will be displayed if the block has been finished.

I remember that jeb made some efforts to write such a debugger but I don't remember if he posted it here at DosTips or somewhere else.

Regards
aGerman

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

Re: Batch DEBUG

#4 Post by einstein1969 » 13 Apr 2014 07:52

thanks aGerman!!

I had completely forgotten about this! But it 's really brilliant!

einstein1969

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

Re: Batch DEBUG

#5 Post by Ed Dyreen » 13 Apr 2014 08:11

While developing I tend to call scripts indirectly, for example;

myScript.CMD

Code: Select all

...
tstMyScript.CMD

Code: Select all

@echo off &setlocal disableDelayedExpansion &set "this=%~n0"
:: (
   start "" /low "%comspec%" /k ^""%this:~3%.CMD" /argName: "argValue"^"
:: )
endlocal
This prevents cmd from closing the console after encountering a syntax error, so I have the chance to read the error message.

Unfortunately the cmd /K option doesn't always work :( :evil:

Post Reply