Computing.Net > Forums > Programming > DOS - batch variables

DOS - batch variables

Reply to Message Icon

Original Message
Name: ehostetter
Date: February 7, 2007 at 09:26:35 Pacific
Subject: DOS - batch variables
OS: XP
CPU/Ram: various
Model/Manufacturer: various
Comment:

i am having to learn DOS and batch programming in a crash-course style, in trying to automate a series of installs i need to do whenever creating a master image. i do have some programming background in BASIC, and more recently, Java.

i have a 'master' batch which instantiates marker variables at 0, one for each program i need to install, then goes through with a series of IF EXIST . . . SET to set the markers to 1 if the program has already been installed.

In the next section, the markers are used to determine which secondary batch file is called (START /WAIT . . . ) to perform the actual install. In theory, after that secondary batch is done, control should return to the master batch and resume on the next line after the START, which checks the marker for the next program on the list.

However, i keep getting caught up short with a "=0 was unexpected at this time." right after the last program is checked for and marker set; it then goes to the next section but stops at the first line and ends. When i inserted a series of SET var lines, to repeat the variables' values (so i could see if they'd set correctly), that error appeared right after them but still before the next section. So it seems that it has something to do with the first section checking the state of the marker to determine whether to call the secondary batch. i can't find a statement there that would display anything.

Each individual batch works fine.

Here's the code. The error occurs at the entry to :instapps, and :dispvar is a temporary section, just to test the validity of the previous marker-setting method. Thanks for any ideas!

========================
:: INITINST.BAT ::
:: Main batch to go through installation of applications required for
:: District images. Specialised apps will have to be manually installed.
:: This file will call other batch-files and remain open; control will
:: return to this file as others complete their jobs.
:: This file will delete itself after Sybase reboot and configuration.
:: 02 feb 2007, eh
:: v1.1 -- 05 feb -- placed aeries install just after office, before novell eh
:: v1.2 -- 05 feb -- discovered loop in :instapps; removed GOTO appcheck; app marker variable will be set to 1 in appropriate batch-files eh

TITLE Main installation script

:: VARIABLE LIST ::
:: %SDC% = SDCS_Tools directory
SET SDC=0
:: %ADO% = Adobe Reader
SET ADO=0
:: %AQT% = Apple QuickTime
SET AQT=0
:: %WMP% = Windows Media Player
SET WMP=0
:: %OFC% = Microsoft Office 2003
SET OFC=0
:: %NOV% = Novell client
SET NOV=0
:: %SQL% = SQL 7
SET SQL=0
:: %EZY% = Aeries/Easy
SET EZY=0
:: %SYB% = Sybase
SET SYB=0
:: 0=uninstalled, 1=installed
:: %SRC% = Batch-file source path
SET SRC=G:\

:: Check for installed applications
:appcheck
::Check for C:\SDCS_Tools
IF EXIST c:\SDCS_Tools SET SDC=1
::Directory exists; reset marker
::Check for Adobe Reader
IF EXIST c:\progra~1\adobe SET ADO=1
::Reader has been installed; reset marker
::Check for Apple QuickTime
IF EXIST c:\progra~1\quickt~1 SET AQT=1
::QuickTime has been installed; reset marker
::Check for Windows Media Player
IF EXIST c:\progra~1\window~2\wmsetsdk.exe SET WMP=1
::WMP10 has been installed; reset marker
::Check for MS Office 2003
IF EXIST c:\progra~1\micros~2 SET OFC=1
::Office has been installed; reset marker
::Check for Aeries
IF EXIST c:\easy SET EZY=1
::Aeries has been installed; reset marker
::Check for Novell Client
IF EXIST c:\novell SET NOV=1
::Novell has been installed; reset marker
::Check for SQL 7
IF EXIST c:\mssql7 SET SQL=1
::SQL has been installed; reset marker
::Check for Sybase
IF EXIST c:\sybase SET SYB=1
::Sybase has been installed; reset marker

:: For testing purposes:
:dispvar
SET SDC
SET ADO
SET AQT
SET WMP
SET OFC
SET EZY
SET NOV
SET SQL
SET SYB

:: Use markers to pick up where installation left off.
:instapps
::SDCS_Tools
IF %SDC%=0 START /WAIT %SRC%copyfld.bat
::Directory hasn't been copied yet; switch to that batch-file.
::Adobe Reader
IF %ADO%=0 START /WAIT %SRC%instado.bat
::Apple QuickTime
IF %AQT%=0 START /WAIT %SRC%instqt.bat
::Windows Media Player
IF %WMP%=0 START /WAIT %SRC%instwmp.bat
::MS Office 2003
IF %OFC%=0 START /WAIT %SRC%instofc.bat
::Aeries/Easy
IF %EZY%=0 START /WAIT %SRC%instezy.bat
::Novell Client
IF %NOV%=0 SET /P NOVAD Does Novell need to be installed? (y/n)
IF /I %NOVAD%==y START /WAIT %SRC%instnov.bat
SET %NOV%=1
::SQL 7
IF %SQL%=0 START /WAIT %SRC%instsql.bat
::Sybase
IF %SYB%=0 START /WAIT %SRC%instsyb.bat

:: Everything is installed and Sybase DS_Edit needs to be configured.
:postsyb
ECHO.
ECHO When the DS_Edit window appears:
ECHO 1. Click OK
ECHO 2. Create a New Server Object with the name of Horizon
ECHO 3. Double-click on the Server Address field
ECHO 4. Click Add
ECHO 5. Into the Network Address field type:
ECHO [deleted]
ECHO 6. Click OK twice
ECHO 7. Close DS_Edit
ECHO.
PAUSE

:: Everything has now been installed and configured except specialised apps.
:finale
CLS
ECHO.
ECHO District standard apps have now been installed.
ECHO Any software specific to this model should now be manually installed.
PAUSE


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: February 7, 2007 at 13:27:02 Pacific
Reply: (edit)

To test for equality:

if %SDC%==0

That's TWO = with no space.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 2
Name: wizard-fred
Date: February 7, 2007 at 13:47:04 Pacific
Reply: (edit)

To return to a bat file it should CALL the second bat. (I am still in W98 so I don't know if that is a requirement for the XP command processor.)


Report Offensive Follow Up For Removal

Response Number 3
Name: ehostetter
Date: February 7, 2007 at 13:57:47 Pacific
Reply: (edit)

i did some serious research on CALL and START, trying to focus on the difference in XP (i have only a DOS 3.1 paper manual!) and it seemed to me that START /WAIT did what i needed it to. i found somewhere that stated that explicitly (extracting from http://www.ss64.com/nt/start.html ):
====
Forcing a Sequence of Programs
If you require your users to run a sequence of 32 bit GUI programs to complete a task, create a batch file that uses the start command:

@echo off
start /wait /b <First.exe>
start /wait /b <Second.exe>
start /wait /b <Third.exe>

Create a shortcut to this batch file and place it on the Start menu or desktop. Set it to run minimized.
When the user double-clicks the shortcut, <First.exe> runs.
When <First.exe> terminates, <Second.exe> runs
When <Second.exe> terminates, <Third.exe> runs
=====

Couldn't find such an explicit statement for CALL. 8/


Report Offensive Follow Up For Removal

Response Number 4
Name: ehostetter
Date: February 7, 2007 at 13:59:08 Pacific
Reply: (edit)

<blockquote>
Response Number 1
Name: Mechanix2Go
Date: February 07, 2007 at 13:27:02 Pacific
Homepage: Golden-Triangle
Subject: DOS - batch variables

Reply:
To test for equality:
if %SDC%==0

That's TWO = with no space.
<blockquote>

Aaaarrrgh! i remember that from Java. Thanks for reminding me; i'll try that. 8)


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: February 7, 2007 at 14:10:42 Pacific
Reply: (edit)

[1] NT is not DOS

[2] there is no START in DOS

[3] there is no GUI in DOS

[4] in DOS, CALL will run another BAT and return control to the calling BAT. IIRR CALL was first available on DOS 3.30

[5] In NT [not DOS] the START runs another app and the BAT continues without waiting for the app to exit.

Try this:

start chkdsk
chkdsk

[6] NT handles CALL just like DOS



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal


Response Number 6
Name: ehostetter
Date: February 7, 2007 at 14:40:40 Pacific
Reply: (edit)

<blockquote>Name: Mechanix2Go
Date: February 07, 2007 at 14:10:42 Pacific
Homepage: Golden-Triangle
Subject: DOS - batch variables

Reply:
[1] NT is not DOS
<blockquote>

Um, this is going to be a stupid question, i just know it: why did NT come up? All the computers i have to set up use XP, and that's all i've referenced.

<blockquote>
[2] there is no START in DOS
</blockquote>

Funny, it shows up here: http://www.ss64.com/nt/ (browser titled "Windows XP Commands" and page titled "An A-Z Index of the Windows NT/XP command line")

<blockquote>
[3] there is no GUI in DOS
</blockquote>

Now, *that* i know. i didn't refer to one.

<blockquote>
[4] in DOS, CALL will run another BAT and return control to the calling BAT. IIRR CALL was first available on DOS 3.30
</blockquote>

Fair 'nuff. i'm willing to try.

<blockquote>
[5] In NT [not DOS] the START runs another app and the BAT continues without waiting for the app to exit.
</blockquote>

1-see first response up there.
2-i know, that's why i tried START /WAIT. i don't want the batch to keep going; i want it to pause until the app has installed, then continue.

<blockquote>
Try this:

start chkdsk
chkdsk
</blockquote>

Um, why? Oh -- to see if START CHKDSK actually gets CHKDSK going?

<blockquote>
[6] NT handles CALL just like DOS
</blockquote>

See the first response above.

Thank you!


Report Offensive Follow Up For Removal

Response Number 7
Name: ehostetter
Date: February 7, 2007 at 15:22:32 Pacific
Reply: (edit)

<blockquote>
Name: Mechanix2Go
Date: February 07, 2007 at 13:27:02 Pacific
Homepage: Golden-Triangle
Subject: DOS - batch variables

Reply:
To test for equality:
if %SDC%==0
</blockquote>

Thanks! That solved it! i really appreciate it!


Report Offensive Follow Up For Removal

Response Number 8
Name: Mechanix2Go
Date: February 7, 2007 at 22:48:27 Pacific
Reply: (edit)

Thanks for letting us know.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: DOS - batch variables

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge