Batch file that runs UEdit on each file not working when scheduled task (solved)

Batch file that runs UEdit on each file not working when scheduled task (solved)


    Aug 17, 2013#1

    First off, UltraEdit is proving to be pretty amazing.

    I've made two macros which work beautifully when ran on files from the command line.

    I've created two .bat files that run the macro for each file in a given folder:

    Code: Select all

    cd c:\wget
    for /f %%f in ('dir /b c:\wget\') do uedit32 %%f /m,e="c:\CRON\2.mac"
    If I double click the .bat file, it runs fine. If I schedule these as tasks to run every hour, the task shows as 'RUNNING'. The files don't get edited and the task never stops running. Yesterday these were running fine as scheduled tasks, they seem to have just stopped working.

    I've checked user permissions, restarted the server (Win2k8r2) and ran the .bats manually to make sure they're still working. Are there any known bugs, or a better way to execute Uedit from the bat files?

    Grand MasterGrand Master

      Aug 18, 2013#2

      Aaarrrggghhh, your batch file is awful.

      UltraEdit is a Windows application and not a console application. Whenever a Windows application is started from within a batch file, a new process is created by Windows and the command line interpreter (cmd.exe) continues immediately with executing the batch file. So you start UltraEdit for processing a file with a macro and while UltraEdit is starting, a new instance of UltraEdit is started with a new file name and a macro to process, and while this second instance is starting a third instance of UE is started, ... awful, really awful.

      May I suggest to use just following command line:

      start "UE Batch Job" /min /wait "Full path to uedit32\uedit32.exe" /fni c:\wget\*.* /m,e="c:\CRON\2.mac"

      start is an internal command of cmd.exe designed for running Windows processes from within a batch file. The first parameter is usually an optional title for the console window opened when running command start. But if any parameter on command line must be enclosed in double quotes because of a space character, the first parameter must be a window title in double quotes or command start will interpret the first string in double quotes as window title.

      /min is a parameter of command start and results in running the Windows process started with a minimized window.

      /wait is another parameter of command start and results in halting execution of the batch file until the called Windows application terminates.

      The next command is the Windows application to start which is UltraEdit. It is better to specify it with full name and complete path as otherwise Windows has to find an executable with name uedit32 in the directories listed on environment variable PATH. The PATH variable value (=list of directories) usually differs from your account to the system account used for running scheduled tasks.

      /fni is a parameter for UltraEdit. It means force new instance. By default the configuration setting Allow multiple instances is NOT enabled and therefore if a second instance of UltraEdit is started and this second instance has read the current value of the configuration setting from uedit32.ini, it looks in list of running processes for an already running instance of UltraEdit and if found, sends this (first) instance a message with the file name to open, before the second instance exits. This single instance behavior is not good if macros or scripts should run in background, see Always get error message when running a macro/script via command line parameter for details.

      UltraEdit supports wildcards on command line and therefore c:\wget\*.* is all you need to open all files in a folder at once in UltraEdit.

      What you need to do now with this command line is to recode your macro a little to run on all opened files instead of active file only.

      If your (first) macro inside macro file c:\CRON\2.mac does not contain already a loop, you can surround your macro by

      IfNameIs ""
      your existing macro code
      CloseFile Save

      With this code your macro is executed in a loop always on active file which is saved and closed. The loop stops if there is a file without name which is either a new, unnamed file (not in this case) or there is no file open anymore (as in this case).

      If your macro contains already a loop, you have to put above code into a second macro stored together with your macro in same macro file. Instead of your existing macro code put into this main loop macro:

      PlayMacro 1 "case sensitive name of your macro"

      This main loop macro named for example RunOnOpenFiles must be defined on the command line:

      start "UE Batch Job" /min /wait "Full path to uedit32\uedit32.exe" /fni c:\wget\*.* /m,e="c:\CRON\2.mac/RunOnOpenFiles"

      By the way: If it is no problem when UltraEdit is started with UE main window being opened normally or maximized as on last exit, you can use in this case also just

      "Full path to uedit32\uedit32.exe" /fni c:\wget\*.* /m,e="c:\CRON\2.mac/RunOnOpenFiles"


        Aug 18, 2013#3

        You sir, are amazing!

        I've never received such a thorough response to anything, ever! I followed all of your advice and not only does this work perfectly, I've learned quite a bit along the way. The macro now runs at a fraction of the time that it was taking before, when it would work. This is great! Thank you!!! :D