Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi folks,
Here's my trouble. I'm trying to write a simple .bat program to solve a minor problem I have, and it's not behaving as I expected it to. Basically, what I want it to do is copy some files, run an .exe, then copy more files. In that order. It uses "copy /y" to copy the files without input (because it is overwriting identical filenames), then it's supposed to run the .exe, then copy different files with "copy /y", also overwriting the same files.
Instead, it terminates as soon as it calls the .exe!! It makes the first copy, then calls the .exe. When the .exe terminates, I'm left staring at my desktop wondering why the second copy was not executed.
I'm running a Windows 98 system. I've been programming .bat files for years now, but I've never seen an error like this. Only possibility that I can think of is this: the executable accesses the copied files (does not write to them, only reads) during execution, and I'm thinking maybe it has not finished with them by the time the copy command tries to overwrite them. I'm not sure about this theory, though.
Does anyone think they can shed some light on this for me?
Kasreyn

Well, first of all, I hope you realise that if this executable you are talking about is a Windows program, the files will continue to be copied in the background when the program is running. This might happen even if it isn't a Windows program if it has a strange .pif file or is one of those files that Windows does strange exceptions to in the way of executing.
Also, you know this too I guess, but make sure that you are actually calling the .exe file and not a .bat file with the same name (which will cause the first .bat not to proceed when the second has finished)
I think you should post the whole bat file here, and also say what the program is supposed to do, and whether it is a Windows program or not.

Ummm...no. I thought maybe hmpxrii knew something I didn't about Windows running a Batch file, but he/she doesn't. Here is my example Batch file (which will show you how to fix your problem...possibly.) Note: I created and ran this on Windows NT Server 4.0.)
[a.bat]
copy a.bat b.bat
call notepad.exe
copy b.bat c.bat
The Batch file copies the first file, then runs notepad and waits for me to close that. When I've closed it, it runs the next line and copies the second file. I underlined the call statement, because without that another program will take over and never return control to the Batch file. Be warned that some programs will still fail to return control to the Batch file. Many years ago (probably 4 or 5 now) I wrote a Batch menuing system that was essentially a security system for my hard drive. (Yes, you can make a security system for Batch - if you use ansi.sys to remap keys and change the text color to black on a black background as I did - it makes it very hard to hurt anything after a Ctrl+C or Ctrl+Break.) Anyway, the moral of this story is that almost everything would return control back to my Batch - except some games that I ran for long periods of time. It's almost like the return was overwritten in memory or that DOS timed out and gave up - dunno. But for most cases, call will do the trick. For the cases where it doesn't work, use QBasic (or better yet, QuickBasic - you can compile QuickBasic to an executable) with the shell command.

Hm ... you might be right there, I don't have access to Windows NT so I can't tell whether one of us are wrong. My solution was intended for (and works with) Windows 95, and I supposed it should work with 98.

Well, I have learnt something strange today:
This example works very well in Windows 95, but (according to an online friend of mine) not in Windows 98:@echo off
copy file1 file2
c:\windows\notepad.exe
copy file2 file3In Windows 98, the batch file terminates at the call for notepad, but if you put a call before the call it works in Windows 98 too. One might wonder why MS decided to implement that.
However, as far as I know, there is no easy way to make sure the batch file does not continue until after notepad (in this case) is terminated without some serious programming.

Try putting a "call" in front of the "c:\windows\notepad.exe" and see if it does anything different. I suppose I have the same problem as you for validating replies. I don't have 95 or 98 or any of those, so I can't test things intended for those operating systems. So you may be right after all in your first post. :)

Ok, here we go, I figured some more stuff out.
I made a test batch file using call and not using call. Here was the test .bat:
@echo off
cd\windows\desktop
copy /y c:\windows\desktop\test.txt test1.txt
pause > nul
call c:\windows\notepad.exe
copy /y test1.txt test2.txt
cls
^ZTest.txt was already in existence when executed. The pause was so I could correctly gauge when it was doing things. I tried it with and without call, without path and with. Every time, it first copied test to test1, then paused. I moved on to execution of notepad. Every time, the batch window behind closed, and about 3 seconds later test2 appeared on the desktop, regardless of whether Notepad was still running. Obviously it's not doing a call-and-return OR a "goto", it's starting a simultaneous execution of notepad.
What I *want* to do is be able to execute an .exe from within a .bat, and have the .bat WAIT until the .exe terminates and returns execution to the .bat. But Windows' multitasking is defeating me. ;-)
Here is the .bat I originally tried to write:
@echo off
cd\games\diablo
copy /y VKMEdlls\*.dll .
VKME
copy /y 1.08dlls\*.dll .
^ZSome explanation, Diablo is a game I own and VKME is a 3rd party modification of it that, among other things, needs some hacked diablo .dll's to run. It also makes it a heckuva lot more fun =). These .dll's are stored in VKMEdlls, while the originals are backed up in 1.08dlls. The idea is to have the .bat swap them for me whenever I run the program so I don't have to fiddle with it anymore. But now that it's causing so many problems, I'm taking it as a personal challenge to make it work! =P I've tried using call vkme.exe, call c:\games\diablo\vkme.exe, nothing works. It fails to make the swap back at the end. Both VKME and Diablo are Win9x 32-bit programs, with high graphics etc and memory usage etc etc like most modern games. I don't know whether this could be causing the .bat errors.
This isn't about the game anymore, this is about making .bat's do what I want them to!! =P Anyone have any ideas?
-Kasreyn.

I have no way of testing this, but try what hmpxrii said originally about making another Batch file to call the *.exe. I dunno if it'll matter or not, but then again Batch isn't sposed to allow multi-tasking like that either. On my NT box it works fine. :P Anyway, the files would look like:
[xxx.bat]
@echo off
cd\windows\desktop
copy /y c:\windows\desktop\test.txt test1.txt
call yyy.bat
copy /y test1.txt test2.txt
cls
[yyy.bat]
call c:\windows\notepad.exe
I honestly dunno for sure how to fix this as I've never run into it before. Perhaps Laurence has and will know - or even better, perhaps the solution suggested by hmpxrii works. :)

You must use the CALL statement for the .exe if you want it to return to the batch file.
eg.
CALL VKME.exe

![]() |
DOS Setup Disk 1!!
|
HELP! Uninst. & Insta...
|

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