I am not encountering an error, but this is my first foray into using your product and I am not sure if the techniques I've gleaned from your examples and forums are the best way of accomplishing what I am trying to do. In its simplest sense, I am trying to create a file and upload it to a website. To complicate this, the file could be created multiple times at very uneven intervals. I run up to a dozen instances of Excel (across multiple machines) which are processing information and which each could create a file to be uploaded which will somehow get into a "starting" directory on the machine with iMacros. Excluding the Excel portion that creates the file, I have split this function into three processes.
Process A: A batch file, looks in a "starting" directory and determines if a file has been created. If one exists, it looks to see if there is room in an "upload" directory to copy it to. If so, it will invoke Process B. If no file is there to start or the upload directory already has a file in it, it waits a while and then checks again.
Process B: Another batch file, does some logging of the file it will be processing and then MOVEs it to the "upload" directory for processing by iMacros in Process C. It then invokes Process C with a command like the following:
Code: Select all
MOVE W:\Starting\AWUpload.dat W:\Uploads\AWUpload.txt ECHO UPLOADING AW FILE start "" /W /B "C:\Program Files (X86)\Mozilla Firefox\firefox.exe" imacros://run/?m=AWUpload.iim REM start "" /W /B "C:\Program Files\Mozilla Firefox\firefox.exe" imacros://run/?m=AWUpload.iim TIMEOUT 15
Since this upload process can take close to half a minute when the website is busy, I want to enable the entire process to support multiple uploads being at least started before the first one has completed. I considered having multiple directories for the files but it seemed that would still need multiple iMacros scripts so that they would know which directory they were working with, so it seems just as simple to just use multiple filenames in the upload directory. I considered having multiple Process A scripts running simultaneously, but I was concerned that I could have these collide with two Process Bs attempting to move the same file from the "starting" directory unless I created some kind of logic to tell each script when a process is already running. Ultimately, I decided it was simplest to have Process A run 3 times (about 10 seconds apart) before looping around to start again, while using triplets of Process B and Process C similar to the following:
Code: Select all
:STARTOVER timeout 9 IF EXIST "W:\Starting\AWUpload.dat" IF NOT EXIST "W:\Uploads\AWUpload1.txt" CALL AWUpload1.bat ECHO will check again in 9 seconds... timeout 9 IF EXIST "W:\Starting\AWUpload.dat" IF NOT EXIST "W:\Uploads\AWUpload2.txt" CALL AWUpload2.bat ECHO will check again in 9 seconds... timeout 9 IF EXIST "W:\Starting\AWUpload.dat" IF NOT EXIST "W:\Uploads\AWUpload3.txt" CALL AWUpload3.bat GOTO STARTOVER
This seems to work. At the current speed at which files might be created, it seems sufficient to handle them all and in testing has not attempted to upload the same file more than once (though that is also a concern since the MOVE command may fail if the file has not yet been deleted by the iim from the prior process a half minute ago and I do not think that will stop the batch file from calling another iim file).
So, my questions are:
- Does this seem like a reasonable approach to this or have I missed some clever feature of iMacros that would have made my life easier? There does not seem to be a command to determine if a file exists before issuing a FILEDELETE so I have to ensure that the batch file does not call Firefox unless the file is there and I need to be sure nothing else deletes it before the iim Macro does. Otherwise, I seem to get hanging iMacros scripts with error messages.
- Is this TAB=1 / TAB CLOSE command pair likely to work as I am expecting it? I have Firefox open with a tab on the home page when this whole process starts and the processing never happens on that first tab; it always opens a new tab, so that part is good. However, I have come back an hour or two later and found an extra tab open at times. I was not expecting TAB=1 to help me, but I thought TAB CLOSE would always close the tab the macro script is working on. Should I add more time before the TAB CLOSE command (or perhaps after it)?
- Am I correct that I needed to clone and then rename the iMacros and the upload files or use some other means to ensure that they would not potentially process /delete the same file or otherwise interfere with another instance of the same script? I chose to name the upload files / batch files / iim files Upload1/Upload2/Upload3 for simplicity, but I can imagine that I might have been able to pass a parameter like the file name to a single script (if this is supported) and then always run AWUpload.iim. Is there a way I could have done that?
- Is there anything you can suggest to make this process cleaner or more robust?