PDA

View Full Version : Problem with a simple batch file


akif
05-08-2009, 03:52 PM
Hi all,

I have an MS Access (mdb) file which i want to get opened after a TXT file.
So i made this batch file including two commands:

instruct.tx
dbfile.mdb

The problem is that this process opens a DOS window in the background, which does not get closed before the "dbfile.mdb" is finally quitted. Is there any way i can make this DOS prompt window to become invisible ?

Thanks in advance.

Paul Komski
05-08-2009, 10:53 PM
Use the start command (http://www.computerhope.com/starthlp.htm). At its most basic and with the batch file in the same folder as the two files:-


start instruct.txt
start dbfile.mdb

akif
05-10-2009, 03:36 AM
Thanks Paul

It did solve my problem.

A step furthre, is it possible to make it sequential ? I mean i want the "dbfile.mdb " not to get openned until the "instruct.txt" file is closed by the user.

Paul Komski
05-10-2009, 05:09 AM
I don't (right now anyway) know of a way to make a batch file create a loop containing a check for whether an application is open or not or to consistently use the /wait switch but if I do then I will post back. The best I can suggest for now is to get the command window to wait for you to press the Enter Key and then close notepad (or whatever) and open the second file. The command window would, of course, need to be made the active window, before pressing Enter, by first clicking on it or its box in the task bar.

start notepad.exe instruct.txt
set /p go=”Press ENTER to continue: ”
taskkill /f /im notepad.exe
start dbfile.mdb

You don't need the full path for programs like notepad, because they are in a system folder, which itself is nearly always itself in the global PATH variable. Nor, obviously, if the path is the same as that where the batch file itself is kept. If you use taskkill any unsaved work will not be saved.

I have specified notepad in the above example because I wanted to ensure that the same program is closed by taskkill. If the application is not made explicit in that way then the default program currently set to open a file would be used. If you want to use another non-default program to open a file then you need to specify it. When using paths to files or applications then enclose them in quotes.

start "C:\Program Files\JGsoft\EditPadLite\EditPad.exe" "C:\mytextfiles\instruct.txt"
set /p go=”Press ENTER to continue”
taskkill /f /im "C:\Program Files\JGsoft\EditPadLite\EditPad.exe"
start dbfile.mdb

The above example (which uses a different non-system text editor) has its path and a path to another specified instruct.txt enclosed in quotes but no quotes round dbfile.mdb because it must be in the same folder as the batch file. Just experiment with changing quotes if wrong things start to happen.

BTW, you can start and stop services under the NT OSes with:-
net start servicename
and
net stop servicename

If doing this you would also probably want to run services.msc and ensure that servicename is set to be opened manually.

You can also open a command prompt and enter start /? or net /? or taskkill /? to get all the options for the various commands.

akif
05-10-2009, 08:29 AM
Thanks again Paul for such a detailed reply.

Well, the simple instruction set:

instruct.tx
dbfile.mdb

was already doing this job (sequential opening), but i disliked the command prompt window to be present there. What i actually wanted was something that would keep this command prompt window out of the scene while maintaining the sequential opening of the two files. With your first post here, i think the closest i could go is by using this:

instruct.txt
start dbfile.mdb

This makes the command prompt window to get close as the instruct.txt is closed.

Best would be to somehow make this command prompt window close (or get invisible, or minimized) right from the begining; not sure if it is possible !? The point was not to confuse the supposedly dumb user from this extra command prompt window.

Paul Komski
05-10-2009, 10:39 AM
If you want the second application to be available after the first one then open the database file first and then the text file. Then when the text file is closed the database window should be there underneath. You can use the sleep command to put a short delay between opening both windows to ensure they do open sequentially. You could also open the second window maximised to ensure the mdb file is completely hidden.

start dbfile.mdb
sleep 1
start /max notepad instruct.txt

There is a way to make a batch file minimize itself but another v. simple way is to use one batch file to call another one but minimized.

Thus file1.bat just has the code:

start /min file2.bat

akif
05-10-2009, 01:28 PM
Thats cool...

The above code (first one) does all that was needed.

Thanks very much!