DOS question: multiple commands on one line

  • Thread starter Thread starter John Goche
  • Start date Start date
J

John Goche

Hello,

On Unix it is possible to specify more than one command
to run at the shell prompt by separating the commands
with semicolons.

Is there a way to run more than one command on from one
line by using a suitable separator or by other means?

Thanks,

JG
 
Not quite. Here are the various connectors:
& Concatenate several commands on the one line.
| The pipe character.
&& Execute the following command only if ErrorLevel=0
|| Execute the following command only if ErrorLevel > 0
 
Fairenough.... thanks for correcting me.


....and you forgot to mention, there is no "DOS" in Win2000... it is the
command interpeter or command line.
"DOS" is an OS.

;-)
 
Thanks!

BTW, what method can I use to view the value of ErrorLevel
and how do I inspect the return value from executables?

Thanks,

JG
 
There are several ways to examine a return value:

c:\Tools\SomeExe.exe || echo This program failed

c:\Tools\SomeExe.exe
if ErrorLevel 1 echo This Program failed

c:\Tools\SomeExe.exe
echo This prgram returned an error level of %ErrorLevel%

The first two methods flag an error if the program returns
an ErrorLevel of 1 or more.
 
Ah yes, I remember a trick for young players. If you want to test
ERRORLEVEL of 1, 2, 3, or 4 you have to do it in reverse order:

if ERRORLEVEL 4 echo errorlevel = 4
if ERRORLEVEL 3 echo errorlevel = 3
if ERRORLEVEL 2 echo errorlevel = 2
if ERRORLEVEL 1 echo errorlevel = 1

From memory, anyway.

Cheers,

Cliff
 
Quite so, and very clunky programming it was. With Win2000
sanity returned:

echo errorlevel=%errorlevel%

With your coding example you actually had to jump out of
the batch file. Without several "goto" statements, an error
level of 4 or higher would generate four separate echo statements . . .
 
Back
Top