Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Syntax checker for MS-DOS batch scripts

7,233 views
Skip to first unread message

Alex Stankevich

unread,
Jul 11, 2011, 11:41:30 AM7/11/11
to
This is a basic question, however, I've been looking through the FAQ,
googling, and reading the CMD.EXE docs, but could not find any
information on how to check the syntax of a bat script without
actually executing it. Is there some way of doing this (e.g.
equivalent to bash -n)?

Thanks,
Alex.

foxidrive

unread,
Jul 11, 2011, 11:59:00 AM7/11/11
to

No.

There are many undocumented techniques and nobdy has written anything to parse a script for typing errors.

I doubt anyone would try as there are just too many variables and ways you can form a script, with any program and syntax.

--
Regards,
Mic

Alex Stankevich

unread,
Jul 11, 2011, 12:18:49 PM7/11/11
to
Is there some sort of a trick where the script can start to run and then hit a PAUSE, but the sole act of invoking it and reaching that step implies the cmd parser validated the syntax?

foxidrive

unread,
Jul 11, 2011, 12:32:15 PM7/11/11
to
On 12/07/2011 02:18, Alex Stankevich wrote:
> Is there some sort of a trick where the script can start to run and then hit a PAUSE, but the sole act of invoking it and reaching that step implies the cmd parser validated the syntax?


No.

Knowing what you need to do might get you some better answers.


--
Regards,
Mic

Todd Vargo

unread,
Jul 11, 2011, 5:54:26 PM7/11/11
to

The Pause/Break key usually will pause a batch in process. Pressing the
enter/return key resumes processing. However, if Alex wants to set up break
points in the batch, the PAUSE command can be inserted in the code at
various junctures for testing purposes.

Timo Salmi

unread,
Jul 12, 2011, 2:05:43 PM7/12/11
to
On 12.07.2011 00:54 Todd Vargo wrote:
>> On 12/07/2011 02:18, Alex Stankevich wrote:
>>> Is there some sort of a trick where the script can start to run and
>>> then hit
>>> a PAUSE, but the sole act of invoking it and reaching that step
>>> implies the
>>> cmd parser validated the syntax?

> The Pause/Break key usually will pause a batch in process. Pressing the

> enter/return key resumes processing. However, if Alex wants to set up
> break points in the batch, the PAUSE command can be inserted in the code
> at various junctures for testing purposes.

There are some simple examples in
108} How can I execute a script one line at a time to debug it?
http://www.netikka.net/tsneti/info/tscmd108.htm
for Alex to look at, in case he has not already done so.

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Home page: http://www.uwasa.fi/laskentatoimi/henkilokunta/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Timo's FAQ materials at http://lipas.uwasa.fi/~ts/http/tsfaq.html

billious

unread,
Jul 12, 2011, 10:22:13 PM7/12/11
to

"Alex Stankevich" <astan...@gmail.com> wrote in message
news:edb27784-4b5b-487c...@glegroupsg2000goo.googlegroups.com...

Beware the fail-to-fail scenario.

Batch is interpreted, logical-line to logical-line. As part of that
interpretation, the values of environment variables may be substituted into
the code. In essence, it's an exercise in self-modifying code.

For instance, as a single line

%var%

is perfectly valid batch syntax. Whether or not it is valid depends entirely
on the contents of the environment variable VAR. You could test for months
and get no problems using a PAUSE, but all you need is the wind blowing in
the wrong direction to make it fail.

And for those who scorn batch and look and point and titter - guess what
happens when you have your favourite compiled HLL construct an SQL query and
execute it.

Tim Meddick

unread,
Jul 13, 2011, 7:13:24 AM7/13/11
to
I thought I'd better mention (in case nobody else does) the fact that
there's always the [/y] switch in COMMAND.COM's options in *pure* MS-DOS
(that is; real-mode MS-DOS & DOS under Windows '95, '98, ME)....

So you can check your batch script under *those* operating systems, using ;

command.com /y /c mybatch.bat [parameters]

...where [mybatch.bat] is your batch file and [parameters] is any thing
else on the command-line you want to pass on to your batch-file.

This results in [command.com] "stepping" through your batch-script,
executing it line-by-line with the option of answering [Y] or [N] to
whether you execute each line.

This option is, of course, limited to the above mentioned OSes, and *not*
under any of the NT-based DOS emulation command-interpreters [cmd.exe] or
even NT-based [command.com].

==

Cheers, Tim Meddick, Peckham, London. :-)


"Alex Stankevich" <astan...@gmail.com> wrote in message

news:4d7d5ed7-d125-488d...@fq4g2000vbb.googlegroups.com...

Todd Vargo

unread,
Jul 13, 2011, 4:45:05 PM7/13/11
to

"Tim Meddick" <timme...@o2.co.uk> wrote:
>I thought I'd better mention (in case nobody else does) the fact that
>there's always the [/y] switch in COMMAND.COM's options in *pure* MS-DOS
>(that is; real-mode MS-DOS & DOS under Windows '95, '98, ME)....
>
> So you can check your batch script under *those* operating systems, using
> ;
>
> command.com /y /c mybatch.bat [parameters]
>
> ...where [mybatch.bat] is your batch file and [parameters] is any thing
> else on the command-line you want to pass on to your batch-file.
>
> This results in [command.com] "stepping" through your batch-script,
> executing it line-by-line with the option of answering [Y] or [N] to
> whether you execute each line.
>
> This option is, of course, limited to the above mentioned OSes, and *not*
> under any of the NT-based DOS emulation command-interpreters [cmd.exe] or
> even NT-based [command.com].

Since this is covered in Timo's weekly batch FAQ, and OP specifically stated
CMD.EXE, it was pointless to post this as a response to the OP's message. If
you really want to be of help to the general public, you might begin with
following accepted Netiquette practices as discussed here...

http://lipas.uwasa.fi/~ts/http/quote.html

FileGod

unread,
Jul 19, 2011, 3:19:59 PM7/19/11
to
[Type your reply here]

I have never heard of a existing syntax checker, it would be neat
to find one & a syntax could be written & it would be pretty much
a spell checker, there are open source spell checkers out there but
another way it could be done is to use a spell checker on properly
working batch files & add the text that is found in the batch files
to the database of the spell checker.

Todd Vargo

unread,
Jul 19, 2011, 4:58:42 PM7/19/11
to

"FileGod" <0@0.0> wrote in message news:j04lcu$k27$1...@speranza.aioe.org...
> [Type your reply here]
^^^^^^^^^^^^^^^^^^^^^^

No, it goes here.

[Type your reply here]

FileGod

unread,
Jul 20, 2011, 3:26:41 AM7/20/11
to
>[Type your reply here]

>"Todd Vargo" <tlv...@sbcglobal.netz> wrote:
>No, it goes here.
>[Type your reply here]

I could swear thats what Farrah Fawcett said...


FileGod

unread,
Jul 20, 2011, 3:45:37 AM7/20/11
to
"Todd Vargo" <tlv...@sbcglobal.netz> wrote:
>No, it goes here.

>[Type your reply here]
Dang, I know I'm tired, it looks like I forgot hot to post.
Shoot, I have been a little depressed, I no longer have my
free web space, I will try to get everything back online
including my Bat2Bash online converter, I had a Heart Attack
so I have not been able to do as much as normal but I'm okay
and should be able to get back to normal after some time...

Tim Meddick

unread,
Jul 20, 2011, 6:29:32 AM7/20/11
to
Well, most things I comment on are "pointless" according to you...

Since you never ever approve, encourage or support anything I have ever
written, I cannot take such prejudicial criticism as a true reflection on
reality, since others are, at least, a little more "balanced" in their
analysis...

==

Cheers, Tim Meddick, Peckham, London. :-)


"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:ivnigt$n9j$1...@news.albasani.net...

foxidrive

unread,
Jul 20, 2011, 6:45:08 AM7/20/11
to
On 20/07/2011 20:29, Tim Meddick wrote:
> Well, most things I comment on are "pointless" according to you...
>
> Since you never ever approve, encourage or support anything I have
> ever written, I cannot take such prejudicial criticism as a true
> reflection on reality, since others are, at least, a little more
> "balanced" in their analysis...
>
> ==
>
> Cheers, Tim Meddick, Peckham, London. :-)


Tim,

You 'arrived' here and immediately got on the wrong side of people
because you don't follow the conventions of the group, and Usenet,
and were argumentative about it.


Somehow you expect to gain respect in this way from the regulars?

You've said several times that people don't comment on your
posts - well you have had more posts commenting about your posts
than anyone here. The fact that they all ask you to follow the
conventions should tell you something.

--
Regards,
Mic

Todd Vargo

unread,
Jul 20, 2011, 4:31:22 PM7/20/11
to

Careful, lest he claim your analysis off kilter too.

--
http://lipas.uwasa.fi/~ts/http/quote.html

billious

unread,
Jul 20, 2011, 10:58:26 PM7/20/11
to

"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message
news:5lyVp.41227$_b7....@newsfe22.iad...

> On 20/07/2011 20:29, Tim Meddick wrote:
[snip]

>
> You've said several times that people don't comment on your
> posts - well you have had more posts commenting about your posts
> than anyone here. The fact that they all ask you to follow the
> conventions should tell you something.
>


The amusing irony here is that he who earned a place in more than one
killfile by wantonly flouting group convention now appears to be
complaining that others are not replying, defying social convention.

Guess Who...

unread,
Jul 22, 2011, 3:21:49 AM7/22/11
to
"Tim Meddick" <timme...@o2.co.uk> wrote:
>Well, most things I comment on are "pointless" according to you...

>Since you never ever approve, encourage or support anything I have ever
>written, I cannot take such prejudicial criticism as a true reflection on
>reality, since others are, at least, a little more "balanced" in their
>analysis...

What?, you think it's just you he does that to, it's normal for Todd
to post something rude like that, he has done it to me & I have even
tried to find online where he live he got me so pissed off before!

Todd Vargo

unread,
Jul 22, 2011, 9:03:33 PM7/22/11
to

Hmm, what are the odds "Guess Who..." is actually Tim?

Tim Meddick

unread,
Jul 23, 2011, 7:32:53 PM7/23/11
to

Surely you're not that paranoid?

.....and, if you're half the "expert" you seem to think you are, surely you
*know* if I'm also posting in another name - or do you think I actually
bother to run round to my local Internet Cafe in order to create my
alternative identity?!....

But seriously, I really do not feel as if I have to pose as anyone other
than myself to create artificial affirmations.

Poor ol' "Guess Who..." - according to you, he doesn't even exist!

==

Cheers, Tim Meddick, Peckham, London. :-)


"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message

news:j0d6kc$2eu$1...@dont-email.me...

DMcCunney

unread,
Jul 29, 2011, 12:17:21 PM7/29/11
to
* Alex Stankevich:

I've never seen one. The closest I'm aware of to something like that is
the full version of JPSoftware's Take Command product, which is a
Windows GUI outgrowth of the older 4DOS shareware command.com
replacement for MS-DOS. The full version includes an IDE and debugger
for batch files. Since one of the things 4DOS/Take Command offers is a
vastly expanded batch language, that can be useful. I suppose it could
be used to debug NT batch files, since the TCC language is a superset,
and TCC should execute standard NT batch files the way CMD would.

See http://jpsoft.com/ for information.

When I'm doing development, I make sure echo is turned on, and replace
the actual lines that will perform actions with echo statements that
simply print the line to the console. I also do things like echo the
value variables are set to. The basic technique is similar to what you
do debugging shell scripts in *nix.

You could probably write a batch file syntax checker using something
like perl that could be used like lint to make sure syntax was correct,
but it would not be able to confirm that the batch file actually did
what you intended. :-)

> Thanks,
> Alex.
______
Dennis

andrew.p...@gmail.com

unread,
Nov 20, 2013, 5:21:53 PM11/20/13
to
command /y /c <file.bat> is pretty cool. There may not be anything NT-compatible for .bat files :(

Does anyone know of a similar, syntax checking feature, for PowerShell scripts?

alexga...@gmail.com

unread,
May 25, 2016, 6:11:36 PM5/25/16
to
Is something wrong with this?

cls
@ECHO OFF
title Shutdown, Restart or Logoff
echo Would you like to Shutdown, Restart, Logoff or Cancel?
set/p "cho=>"
if %cho%==Restart goto Restart
if %cho%=Shutdown goto Shutdown
if %cho%==Logoff goto Logoff
if %cho%==Cancel goto Cancel
if else goto FAIL











:Restart
echo Restarting...
shutdown.exe /r

:Shutdown
echo Shutting Down...
shutdown.exe /p

:Logoff
echo logging Off
shutdown.exe /l

:Cancel
taskkill /im cmd.exe

:FAIL
echo Invalid Choice

foxidrive

unread,
May 25, 2016, 10:20:43 PM5/25/16
to
On 26/05/2016 08:11, alexga...@gmail.com wrote:
> On Tuesday, July 12, 2011 at 1:41:30 AM UTC+10, Alex Stankevich wrote:
>
> Is something wrong with this?

Well it has nothing to do with the quoted portion. :)


1) "if else" is not needed and is incorrect syntax.

2) In all usual cases "goto :EOF" should be the last command in each
subroutine, as it stops the execution falling through to the next subroutine.
0 new messages