Computing.Net > Forums > Disk Operating System > HELP ME WITH DOS BATCH FILES LINES PLEASE

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

HELP ME WITH DOS BATCH FILES LINES PLEASE

Reply to Message Icon

Name: RON
Date: March 19, 2000 at 11:43:14 Pacific
Comment:

Hi
I am studying dos and I need your help:

What does the following batch file line will do?
IF %1#==# GOTO

Also
In a batch file what %2 means...

I really would appreaciate your help
Thank you
Ron.



Sponsored Link
Ads by Google

Response Number 1
Name: Ryan Cooley
Date: March 19, 2000 at 20:11:38 Pacific
Reply:

Normally I don't do other people's homework for them, but I'll make an exception since this won't take long...

IF %1#==# GOTO
If %1#==# means if the variable and the # are equal to the # (which can only be if the variable %1 is not set (equals nothing). GOTO is meaningless without the word after it. GOTO EXIT would send the batch file to the line that starts with :EXIT
%1 is whatever is typed after the actual command (in the command DIR /W /S /A DIR is the command, /W is %1, /S is %2 and /A is %3. This pattern goes on up to %9 (For future reference, %0 is whater command was typed, in command above in bold, %0 would be DIR /W /S /A


0

Response Number 2
Name: Jon Wetherbee
Date: April 1, 2000 at 13:00:41 Pacific
Reply:

The IF command compares values in a logical expression to determine a TRUE or FALSE result. If the result is TRUE, the command to the right of the IF is performed. If the result is FALSE, the IF command does nothing.

In .BAT files numbers from 1 to 9 with the percent sign (%) before them are variables representing the parameters following the .BAT file name on the command line. For exanple:

C:> mybat.bat 12 37 /s ok

Withing the MYBAT.BAT:
%1 has the value 12
%2 has the value 37
%3 has the value "/s"
%4 has the value "ok"

These values replace the variable name in the command line when the command is executed. If in your example the first parameter to the command file was 93 then:

IF %1#==# GOTO

becomes:

IF 93#==# GOTO . . .

The "#" character is added so that, if there is no parameter given and %1 is null, the IF command will still have an operand on both sides of the comparison operator (==). Again, in your example, if no parameter is given and %1 in null, the IF command look like this:

IF #==# GOTO . . .

Without the "#", it would look like:

IF ==# GOTO . . .

and this would be an invalid command because there is no value on the left side of the operator.

The GOTO command causes execution of the .BAT file to jump to a label located somewhere in the .BAT file. For example:

IF %1#==# GOTO DONE
:
:
:DONE
EXIT

This will test the first parameter and, if it is null, jump to the end of the .BAT file where execution ends with the EXIT command.

The GOTO command must have a label following it or will be reported as an invalid command.


Also In a batch file what %2 means...

See above about parameters passed to the .BAT file.

Hope this helps.


0

Response Number 3
Name: Brian
Date: December 6, 2000 at 16:55:28 Pacific
Reply:

I have written a DOS Batch File that executes a program several times, each time passing a different set of parameters.

My problem is instead of executing the first command line and waiting until the process is finished, it tries to execute the program immediately and eventually crashes.

I have been able to work around the problem using Pause, but I really don't want to have to watch it run.

Any suggestions would be appreciated.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: HELP ME WITH DOS BATCH FILES LINES PLEASE

HELP!! Batch Files www.computing.net/answers/dos/help-batch-files/13176.html

Dos Batch File Commands www.computing.net/answers/dos/dos-batch-file-commands/11921.html

Batch file - search for file www.computing.net/answers/dos/batch-file-search-for-file/12094.html