<--- Turn the page     (contents page)     Turn the page --->


Batch Files/DOS





Come Back Rebooting
Have you ever written a batch file to install some files and/or then modify the autoexec.bat file, want to reboot the system, and to find that the user has to find his/her way back to where they were before the reboot? How about we create a few small batch files to fix this!

Let us say that you are in a directory call NewGame and you have modified the autoexec.bat file to include your path in the PATH= environment variable. Now you want to reboot the machine, once rebooted, run the new autoexec.bat file as normal but then come back to NewGame and test your additions. Assuming that your autoexec.bat file does not have a line in it to call Windows (we're talking true DOS here), you can make a copy of autoexec.bat and name it autoexec.old. Then using the append to file redirect, copy the lines:
CD\NewGame
testit
to the autoexec.bat file. Then when the machine reboots, it will come back to your directory and you can continue with the installation.

However, you now have to delete the autoexec.bat file and rename the copy (autoexec.old) back to autoexec.bat or everytime the machine reboots, it will 'come back' to your directory and try to finish the installation.

Here is some sample batch script for the reboot batch file:
copy c:\autoexec.bat c:\autoexec.old
echo CD\NewGame >> c:\autoexec.bat
echo testit >> c:\autoexec.bat
reboot
How about the testit batch file:
del c:\autoexec.bat
ren c:\autoexec.old autoexec.bat
:: continue with installation.
Now this is just a simple example to show you how it can be done. The more complex you get, the more work you will have to do to preserve the original settings. Also, you can include QBASIC script in your batch files by creating a temp file, echoing source to it, and then calling QBASIC. See the next article in this month's column to find out how.


QBASIC in my Batch files?
Have you ever wanted to do something in your batch file that the batch script just wouldn't allow but you could easily do it in QBASIC? How about this simple example that prints Hello World to the screen.

:: This is a simple batch file
::  that shows you have to include
::   QBASIC script in your batch files.
@echo off
echo 'demo .bas file > demo.bas
echo print "Hello World" >> demo.bas
echo system >> demo.bas
qbasic /run demo
del demo.bas

This batch file will create a file named DEMO.BAS, echo a rem statement, a print "Hello World" line and a system line to it. Then it will call qbasic and run the program and exit.

Notice that we had to put the system command at the end of our script. If we did not, qbasic would run our program and then just sit there and wait for user input.

Now of course you can print Hello World to the screen using just batch file script, but this is just a demo, isn't it? ¥



<--- Turn the page     (contents page)     Turn the page --->

Page 8