Programming helpful tool suggestions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Programming helpful tool suggestions

#16 Post by Samir » 27 Nov 2013 12:41

lol! :shock: :shock: :shock: :shock: :shock:

I see your point. I guess it would only help basic batch file development. :(

penpen
Expert
Posts: 1995
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Programming helpful tool suggestions

#17 Post by penpen » 27 Nov 2013 14:41

Samir wrote:Which editor has batch syntax highlighting? I want!

I have Visual Studio 6.0, and downloaded a batch highlighter extension, but i didn't found it anymore.
But this is an highlighter Extension including *.bat:http://visualstudiogallery.msdn.microsoft.com/6706b602-6f10-4fd1-8e14-75840f855569
Hopefully working with the 2010 expresss version:http://www.visualstudio.com/de-de/downloads/download-visual-studio-vs
I haven't tested the above Versions, but it may be usefull.

penpen

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Programming helpful tool suggestions

#18 Post by Samir » 27 Nov 2013 15:04

penpen wrote:
Samir wrote:Which editor has batch syntax highlighting? I want!

I have Visual Studio 6.0, and downloaded a batch highlighter extension, but i didn't found it anymore.
But this is an highlighter Extension including *.bat:http://visualstudiogallery.msdn.microsoft.com/6706b602-6f10-4fd1-8e14-75840f855569
Hopefully working with the 2010 expresss version:http://www.visualstudio.com/de-de/downloads/download-visual-studio-vs
I haven't tested the above Versions, but it may be usefull.

penpen
Thank you for the links! I was hoping for a notepad++ extension.

julesverne
Posts: 81
Joined: 19 Nov 2013 00:41

Re: Programming helpful tool suggestions

#19 Post by julesverne » 27 Nov 2013 15:10

Samir,

My notepad++ comes with keyword highlighting. Not necessarily syntax highlighting. Some examples it highlights FOR or SET, variables. It doesn't tell you if they're wrong. It is helpful though.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Programming helpful tool suggestions

#20 Post by Samir » 27 Nov 2013 21:58

julesverne wrote:Samir,

My notepad++ comes with keyword highlighting. Not necessarily syntax highlighting. Some examples it highlights FOR or SET, variables. It doesn't tell you if they're wrong. It is helpful though.
I've seen that before, and I know notepad++ has extensions, so I was hoping someone built one for batch. :(

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Programming helpful tool suggestions

#21 Post by brinda » 27 Nov 2013 23:01

great to be back on this lively forum. Using one of tool dbenham recommended in one of the post here

http://www.contexteditor.org/

free and works for me

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Programming helpful tool suggestions

#22 Post by foxidrive » 28 Nov 2013 02:28

Samir wrote:Which editor has batch syntax highlighting? I want!


PsPad was one I've played with, and Notepad++ has syntax highlighting too doesn't it?

I don't use an editor with syntax highlighting myself so I can't suggest one from experience.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Programming helpful tool suggestions

#23 Post by Aacini » 28 Nov 2013 17:54

julesverne wrote:Sorta seems there should be a file checker, like a spell checker in word. Highlight possibly missing a variable symbol here or this echo will echo nothing, this variable will be empty. AutoHotKey at least runs a check first (of the whole file) before running, it even points to where the issue is. Just seems odd that no one has created a program like this yet for bat...


When I saw this request at first I thought that the solution was quite hard: it requires to duplicate the Batch file parser programmed into cmd.exe! However, if the parser is already there, is there any way to use it in order to show the errors in a Batch file? We could execute the Batch file and try to identify the displayed errors in some way. Well, to achieve this point we would require:

  • Trace the execution of the Batch file line by line; this is achieved deleting the "@echo off" command.
  • Differentiate the command-lines displayed by the tracing from the normal output of the program; this is done via a "prompt=id" command with a certain identifier.
  • Differentiate error messages sent to Stderr from the rest of the output; this is achieved via this trick.

This way the reviewer program may take a Batch file, slightly modify it in order to perform previous steps, execute it and store the output in a file. Then, review the file and report any errors found besides the lines that produce they. Here it is:

Code: Select all

@echo off

rem LintBat.bat: Detect syntax and run-time errors in a Batch file
rem Antonio Perez Ayala

if "%~1" neq "" goto begin
echo Detect syntax and run-time errors in a Batch file
echo/
echo LintBat.bat batchFile parameters
echo/
echo The first line in the batchFile must be "@echo off" and it must not
echo output lines with "number:" at beginning.
echo/
echo The lines reported as "errors" are the ones sent to Stdout
goto :EOF

:begin
setlocal DisableDelayedExpansion

rem Copy the Batch file replacing first line with "prompt=0:"
(
   echo set "@prompt=0:"
   for /F "usebackq skip=1 delims=" %%a in (%1) do (
      set "line=%%a"
      setlocal EnableDelayedExpansion
      echo !line!
      endlocal
   )
) > _batchFile.bat

rem Execute the Batch file and redirect all output to a text file,
rem differentiating command-lines with "0:" prefix
rem and error messages with "#:" (number) prefix
shift
(call _batchFile.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 2>&1 1>&3 | findstr /N "^") > output.txt 2>&1
del _batchFile.bat

rem Process the output: when an error message appear, show it with the last command line
setlocal EnableDelayedExpansion
set nextError=1
for /F "tokens=1* delims=:" %%a in (output.txt) do (
   ver > NUL
   set /A "id=%%a" 2>NUL
   if !errorlevel! equ 0 if !id! leq !nextError! (
      if !id! equ 0 (
         setlocal DisableDelayedExpansion
         for /F "delims=" %%c in ("%%b") do endlocal & set "commandLine=%%c"
      ) else if !id! equ !nextError! (
         echo ERROR #%%a: %%b
         echo At line:  !commandLine!
         echo/
         set /A nextError+=1
      )
   )
)
del output.txt

When I tested this program with several small Batch files it produce the desired output! :shock: :D

However, when I tested larger Batch files I encounter some problems: obviously, the redirections performed in the Batch file interfere with the redirections required to differentiate the error messages, although not in all cases. Ok. I deleted any redirections in the Batch files in order to test the reviewer program...

Then, it seems that when a subroutine is called, the error messages produced in the subroutine are displayed after the subroutine return to the main file! :evil:

It is necessary to achieve more tests with this method to identify the problems and try to find solutions to them...

Antonio

julesverne
Posts: 81
Joined: 19 Nov 2013 00:41

Re: Programming helpful tool suggestions

#24 Post by julesverne » 28 Nov 2013 22:30

WHOA!! Aacini! I'm so psyched at the possibility of this. Not just for me, but for all of us who spend countless hours trying to debug just to find out it was one character off or whatever. However, I say "possibility" because I saw this and threw everything else out the window on Thanksgiving to test. Except.. I must be doing something wrong because it's failing as soon as I double click on it. I also tried throwing a .bat of mine on it and failed instantly as well. What am I doing wrong? I think it would be awesome to have people get involved and test this.

UPDATED: I added a pause before the exit /b and that seemed to help. I drop bat file I'm testing onto your bat file. I've got two files now. a _batchFile.bat file and an output.txt file. Taking time now to understand those.

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Programming helpful tool suggestions

#25 Post by Endoro » 29 Nov 2013 06:11

two more editors, for whom it may concern
Komodo, freeware
EditPlus, payware

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Programming helpful tool suggestions

#26 Post by Samir » 29 Nov 2013 08:48

brinda wrote:great to be back on this lively forum. Using one of tool dbenham recommended in one of the post here

http://www.contexteditor.org/

free and works for me
Thank you for the link! This one seems like it will be cool to use. 8)

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Programming helpful tool suggestions

#27 Post by Samir » 29 Nov 2013 08:56

Aacini wrote:
julesverne wrote:Sorta seems there should be a file checker, like a spell checker in word. Highlight possibly missing a variable symbol here or this echo will echo nothing, this variable will be empty. AutoHotKey at least runs a check first (of the whole file) before running, it even points to where the issue is. Just seems odd that no one has created a program like this yet for bat...


When I saw this request at first I thought that the solution was quite hard: it requires to duplicate the Batch file parser programmed into cmd.exe! However, if the parser is already there, is there any way to use it in order to show the errors in a Batch file? We could execute the Batch file and try to identify the displayed errors in some way. Well, to achieve this point we would require:

  • Trace the execution of the Batch file line by line; this is achieved deleting the "@echo off" command.
  • Differentiate the command-lines displayed by the tracing from the normal output of the program; this is done via a "prompt=id" command with a certain identifier.
  • Differentiate error messages sent to Stderr from the rest of the output; this is achieved via this trick.

This way the reviewer program may take a Batch file, slightly modify it in order to perform previous steps, execute it and store the output in a file. Then, review the file and report any errors found besides the lines that produce they. Here it is:

Code: Select all

@echo off

rem LintBat.bat: Detect syntax and run-time errors in a Batch file
rem Antonio Perez Ayala

if "%~1" neq "" goto begin
echo Detect syntax and run-time errors in a Batch file
echo/
echo LintBat.bat batchFile parameters
echo/
echo The first line in the batchFile must be "@echo off" and it must not
echo output lines with "number:" at beginning.
echo/
echo The lines reported as "errors" are the ones sent to Stdout
goto :EOF

:begin
setlocal DisableDelayedExpansion

rem Copy the Batch file replacing first line with "prompt=0:"
(
   echo set "@prompt=0:"
   for /F "usebackq skip=1 delims=" %%a in (%1) do (
      set "line=%%a"
      setlocal EnableDelayedExpansion
      echo !line!
      endlocal
   )
) > _batchFile.bat

rem Execute the Batch file and redirect all output to a text file,
rem differentiating command-lines with "0:" prefix
rem and error messages with "#:" (number) prefix
shift
(call _batchFile.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 2>&1 1>&3 | findstr /N "^") > output.txt 2>&1
del _batchFile.bat

rem Process the output: when an error message appear, show it with the last command line
setlocal EnableDelayedExpansion
set nextError=1
for /F "tokens=1* delims=:" %%a in (output.txt) do (
   ver > NUL
   set /A "id=%%a" 2>NUL
   if !errorlevel! equ 0 if !id! leq !nextError! (
      if !id! equ 0 (
         setlocal DisableDelayedExpansion
         for /F "delims=" %%c in ("%%b") do endlocal & set "commandLine=%%c"
      ) else if !id! equ !nextError! (
         echo ERROR #%%a: %%b
         echo At line:  !commandLine!
         echo/
         set /A nextError+=1
      )
   )
)
del output.txt

When I tested this program with several small Batch files it produce the desired output! :shock: :D

However, when I tested larger Batch files I encounter some problems: obviously, the redirections performed in the Batch file interfere with the redirections required to differentiate the error messages, although not in all cases. Ok. I deleted any redirections in the Batch files in order to test the reviewer program...

Then, it seems that when a subroutine is called, the error messages produced in the subroutine are displayed after the subroutine return to the main file! :evil:

It is necessary to achieve more tests with this method to identify the problems and try to find solutions to them...

Antonio
Very nice! This is still quite helpful since I usually test each 'function' of a batch separately before piecing them together in a larger batch.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Programming helpful tool suggestions

#28 Post by Samir » 29 Nov 2013 08:59

Endoro wrote:two more editors, for whom it may concern
Komodo, freeware
EditPlus, payware
Looks like Komodo is only a trial?

Post Reply