|
Answer» I have a batch file that executes the same command several times and redirects the output to a text file. This used to work flawlessly. Now, after the first time it executes, it says that the file is in use by another process. I ran the batch file without redirecting the output, and it works. So it seems to be narrowed down to the ">" operator. Why is this holding my file open? And how do I fix it?
EXAMPLE: foo.exe > bar.txt <--This one works foo.exe >> bar.txt foo.exe >> bar.txt foo.exe >> bar.txt foo.exe >> bar.txt foo.exe >> bar.txt <--This one also works; all the ones in between have the errorAt first glance nothing seems to be wrong.
What OS are you using? What program does FOO.EXE represent? Is FOO homegrown or part of a commercial product or downloaded from the net?
More info needed. 8-)
After 25 years, it probably safe to say that Microsoft's redirection code is reasonably stable.The OS is XP Pro. Foo.exe represents a program which retrieves information from a proprietary external device, and prints it to the standard output. To my knowledge, it does not touch any files.
My current solution is to sleep for a few milliseconds between each call, but with enough iterations, it's costing a lot of time.My suggestion would have been to sleep the batch file between program calls as I suspect this is a timing problem.
You mentioned that this used to work. What changed? OS? Code change to FOO?
My best guess is that FOO is not using the the DOS functions for it's output. Also I am only aware that redirection was for output to the console not the printer.
Maybe someone will happen by with some other ideas. Hmm. It used to work, and then we ghosted the box to factory settings. I think your best guess is right. Foo.exe was originally written for UNIX and then ported over to WINDOWS. Looking at the code, it looks like it relies on some UNIX libraries which I don't have access to, but its output is through PRINTF, which would be the console, right?
Regardless, shouldn't a batch file wait until the process returns before continuing on to the next command?
Thanks for your help.
Quote Regardless, shouldn't a batch file wait until the process returns before continuing on to the next command?
In theory yes. It seems this redirected output file has no connection to FOO and it's Windows thats opening the redirected file because of the reference on the program call and it's Windows that's closing it, but doesn't get to it right away. This would account for the file being open when the next FOO starts.
Just a thought. 8-)Would the Conditional Processing Symbols & or && be of use :-?
See here.
In the end, it was explorer.exe that had the file open. If there's a window open in the background with the containing folder, it seems Windows keeps checking on the file each time it's updated, so it takes control over the file. With all Explorer Windows closed, it works again.
Thanks for all your help
|