1

I have a batch file which generate so many erros. I have tried some batch IDE, but no clue which code is wrong. I need something like netbeans for java, Visual Studio for VB and C#, etc. What should I use for batch file? I can't see what is wrong, but the error ie.

'else' is not recognized as an internal or external command,

appears. It really painful to code without IDE since I need to prepare files and setting so many things to testing. What I need is something like error suggestion like this picture below but for batch file:

error suggestion

So, if my "if else" block is wrong, tell me please that my if else is not proper before I test the batch file directly.

Need suggestion please, maybe online tools is ok. Like HTML validator, JSON validator is ok. I need validator for batch file. Offline tool or IDE is better.

toha
  • 5,095
  • 4
  • 40
  • 52
  • 2
    What does an IDE have to do with anything? You can't fix an error without an IDE? – Cody Gray - on strike Feb 13 '16 at 13:54
  • 2
    Possible duplicate of [How can I debug a .BAT script?](http://stackoverflow.com/questions/165938/how-can-i-debug-a-bat-script) – Cody Gray - on strike Feb 13 '16 at 13:54
  • https://jpsoft.com/help/ide__batch_debugger.htm and http://www.codeproject.com/Tips/888466/Batch-IDE – toha Feb 13 '16 at 14:05
  • I need IDE which give suggestion when my code is typo, not complete, error like netbeans for java, php, html, or visual studio for c# or vb. Can You help me please? – toha Feb 13 '16 at 14:06
  • Bad news; there is no such thing as a good batch IDE because a lot of batch involves abusing the language to get it to do things it wasn't designed to do. Most things calling themselves batch IDEs will just be holding you back. – SomethingDark Feb 13 '16 at 14:10
  • 2
    I thought a batch IDE was just a command prompt. It has that "immediate execution" feature so highly touted in popular IDEs. And prints all the errors directly to the screen. It even has multiple window support. – Cody Gray - on strike Feb 13 '16 at 14:27
  • Well, you are right: the Batch "IDE" _is_ the command prompt that has the "immediate execution" feature when you enter the name of the Batch file and it prints all errors directly to the screen. After an error in a command you may enter `HELP command` or `COMMAND /?` and a detailed explanation of the command is displayed on the screen; for example: `HELP IF`. Of course, you need to learn how to use the command prompt (in the same way as with any other "IDE"). – Aacini Feb 13 '16 at 14:46
  • I think [Sublime Text 2](http://www.sublimetext.com/2) is a good editor for batch, mainly because the highlight other words that are the same, which helps finding misspelled variables. – Dennis van Gils Feb 13 '16 at 15:11
  • SomethingDark : Yes, that is the problem. Dennins : Yes, that Text Editor is helpful, I have tried using Notepad++ too. Maybe I need something better than just text editor (if any). Since I got error on my code, and no suggestion from notepad++ or another ide I've tried, I try to move on and search better tool. I will try another tool. – toha Feb 13 '16 at 15:45
  • 1
    Although not perfect, there also exists [BatCodeCheck](http://www.robvanderwoude.com/battech_batcodecheck.php), which takes care of some, but not all, errors – Dennis van Gils Feb 13 '16 at 15:59
  • Thank You Dennis. This tool is closest tool to help me out from this case. If I use "run" with batch IDE, to validate typo on my code, if there are 100 things to be set up for test, it wasting time to rollback and prepare 100 files for next testing. That is what I mean. Even the "else" case is not detected using BatCodeCheck, this tool is one step closer to my case. – toha Feb 13 '16 at 16:19
  • 1
    I bet if you read the help file for the IF command you would see what the **proper** syntax was for using the `IF ELSE` construct! – Squashman Feb 14 '16 at 01:46

4 Answers4

3

I suppose you have to remove line breaks between 45 and 46, 40 and 41, 35 and 36, 30 and 31, 19 and 20.

This my sample code works well:

if exist 123 (
  echo 1
) else (
  echo 2
)

And that code with line break before else generates error "'else' is not internal or external command":

if exist 123 (
  echo 1
)
else (
  echo 2
)

Here is a way to still keep line breaks - add ^ character at the end of line before 'else' - that also works for me:

if exist 123 (
  echo 1
) ^
else (
  echo 2
)
kay27
  • 897
  • 7
  • 16
  • Nice suggestion, Sir. Can You tell me what is best Batch IDE please? – toha Feb 13 '16 at 13:51
  • Thanks you, Sir! I'm using [Far Manager 3](http://farmanager.com) with just syntax highlighting and I couldn't suggest any IDE. – kay27 Feb 13 '16 at 14:02
0

I don't know of any IDE (Integrated Development Environment) or text editor which validates batch files and therefore read the comments here very interested.

But even an IDE like VisualStudio or Eclipse does not find all errors in C/C++ code on typing found later by the C/C++ compiler on compilation.

And because of %variable% being expanded before being interpreted by command processor resulting in modifying batch code during execution (more or less), no batch validator can ever find all possible errors which can occur on batch execution.

Well, the usage of a good text editor like UltraEdit highly customized for batch file editing as I have done

  • with syntax highlighting (not perfect, but perfect is impossible for batch files),
  • with automatic usage of OEM code page (instead of ANSI as for other text files even in same instance),
  • with automatic indent and unindent of blocks,
  • with the possibility to reindent a batch code block or an entire batch file by usage of a single command,
  • with auto-completion for often needed commands,
  • with using smart templates for often needed structures like for IF and FOR commands,
  • with a function list listing all well defined labels and subroutines,
  • with the possibility to run edited batch file from within UltraEdit with or without parameters via a user tool and
  • with the possibility to write a script for checking syntax of a batch file or running a third-party tool to check the batch file syntax (not used by me)

is definitely a big help on efficiently writing batch code. But testing the batch files in a command prompt window with various input data and sometimes with echo being enabled to see what is going on during batch execution is very often nevertheless necessary.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • The use of tools like this one does not help you to write _better code_, but may aid that you become more lazy. If you use no additional tools you will learn the intricacies of write correct code sooner or later, and not just Batch code. The use of any aid that replaces your thinking process will always lead to worst solutions, not better ones. Just my opinion... – Aacini Feb 13 '16 at 19:54
0

I'm not sure whether this is what you are looking for. Appreciate your reply if this helped.

Take Command/ Batch Debugger

Or if you need only a text editor, I'd suggest Notepad++ Very simple and straight forward application.

The Godfather
  • 873
  • 11
  • 18
0

Take a look at Batch Compiler it is a complete IDE with a built in compiler and debugger. You can compiler your batch scripts to stand alone executables with version info, admin manifest, silent console mode and so many features. The best thing about Batch Compiler is it's free.

Screenshot of the IDE:

1

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53