4
1
Ever since I moved to Windows 7, whenever I am am developing a .bat script I have exactly one chance to get it right. As soon as I execute the script, it becomes locked by an unknown process even if the execution appears to have completed, and I have to force quit explorer or restart to be able to edit the .bat file again.
For example, if I create a .bat file,
@echo off
@start prog\ConsolePortable\ConsolePortable.exe
then realize after executing it that I needed to change some aspect of the script,
@echo off
@cd prog\ConsolePortable
@start ConsolePortable.exe
Then I will not be able to save my changes. For example, in gvim I get the message, "'console.bat' is read-only (add ! to override)," and then when I try to override, I get the message, "E212: Can't open file for writing."
Surely there must be some way of scripting without requiring ProcessExplorer on every computer I use. How does one find the process of a .bat file to stop it, anyway? I tried ProcessExplorer and BSOD'd the compy trying to stop it. I have also tried using cmd /c in place of start.
EDIT: ConsolePortable starts fine here and appears to exit fine, however the following test setup does not freeze the editor:
// Program.java
class Program {public static void main(String[] args) {System.exit(0);}}
// startProgram.bat
echo Starting Program in Java ...
start java Program
echo exiting bat file ...
EDIT 2: Perhaps I should mention that I created the file by using the touch command in cygwin. After restarting the computer, I can't duplicate this problem, though I have encountered it on other computers before.
Do you test the batch file in a fresh
cmd
window? I'm not exactly sure what the syntax would be, but you could add a command at the end of the .bat to spawn a freshcmd
window (for the next run) and kill the old one, which should free up the file. – jonsca – 2011-06-13T10:31:30.997I had not tried that; I had been double clicking on it. I will try that ... – Peter Nore – 2011-06-13T10:34:14.113
3
I would be looking at your "ConsolePortable.exe" program and make sure that it is exiting properly. Also, have a look at Why won't cmd exit after execution of batch file?
– Mokubai – 2011-06-13T10:35:52.6101Where are you saving the .bat files to? If it's in a sub-folder of Program Files, Win7 doesn't allow editing by default. I have had it, on occasion, allow me to add new files, but not save or edit existing files in those folders. – BBlake – 2011-06-13T11:53:56.173
@Mokubai I have had a look at that link; misterjaytee recommends using start as above. How do I make sure an .exe is exiting properly? Is there an error log somewhere? – Peter Nore – 2011-06-13T12:04:10.357
That's what I thought
start
should be doing, but it appears that in this case there is something weird going on and that program is the only thing that could be doing it. – Mokubai – 2011-06-13T12:08:12.380You can use aforementioned Process Explorer to find out which process locks your .bat file (Menu|Find|Find a Handle or DLL command or simply press Ctrl+F and type in the name of your script). Then it should be clearer what to do. One thing I can tell at the moment is that cmd.exe itself does not lock .bat/.cmd files it executes. – Igor Korkhov – 2011-06-13T12:22:29.630